Tag Archives: sed

Grep through files and replace

Want to replace recursively http://example.co.uk with http://10.0.0.7 and also create backups of the files modified: grep -rFl “http://www.example.co.uk” /path  | xargs sed -i.bak ‘s/http:\/\/www.example.co.uk/http:\/\/10.0.0.7/g’

Posted in Linux | Tagged , , | Leave a comment

Escape special characters inside folder/file name variable

array=(`find /path/ -mindepth 2 -maxdepth 2 -type d -print | sed -e ‘s;[^/]*/;;g’ |  sed ‘s/&/\\&/’`) ( sed ‘s/&/\\&/’  replaces & with \& in the folder/file name )

Posted in Linux | Tagged , | Leave a comment

Remove/replace all characters before and after a specific character & Deal with “postfix/smtpd too many errors after UNKNOWN from unknown”

Plenty of logs on an e-mail server like the one below: Sep  3 05:31:01 web postfix/smtpd[7858]: too many errors after UNKNOWN from unknown[42.119.175.103] (These logs seem to be caused by botnets trying to send spam, or broken spam bots trying … Continue reading

Posted in Linux | Tagged , , | Leave a comment

Remove or replace all characters after character X

ls | sed -e ‘s/X.*//’    (remove) ls | sed -e ‘s/X.*/Y/’ (replace with Y)

Posted in Linux | Tagged , | Leave a comment