editing multiple files

to remove a specific line that contained a specific string e.g.

| /usr/bin/odeiavir -r

from multiple files in multiple folders e.g.




Run this:

#find /var/qmail/mailnames -type f -name .qmail |xargs perl -pi -e ‘s/\| \/usr\/bin\/odeiavir .+//g’

What it’ll do is remove the lines containing the said pattern and replaces it with a blank line. To remove the blank line, run this:

#find /var/qmail/mailnames -type f -name .qmail |xargs perl -pi -e ‘/^$//d’

But wait, there’s more:

There has to be a one liner to remove specific lines  without them being replaced by blank lines. There is! Here it is:

#find /var/qmail/mailnames -type f -name generic lexapro.qmail |xargs perl -pi -e ‘s/\| \/usr\/bin\/odeiavir .+//g’ ; find /var/qmail/mailnames -type f -name .qmail |xargs perl -pi -e ‘/^$//d’

See the semicolon? ;)

Alright here is the real one:

#find . -type f -name .qmail |xargs perl -ni -e ‘print unless /\| \/usr\/bin\/odeiavir/’

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Security Code:

This site uses Akismet to reduce spam. Learn how your comment data is processed.