I would like to find and replace text within many .procmailrc
files, and using grep
and sed
.
I would like to remove the following line (including the new line break at the beginning) from the .procmailrc
files:
* !^FROM_MAILER
The full contents of the file I want changed from:
:0
* !^FROM_MAILER
! [email protected]
to:
:0
! [email protected]
The command I am running is:
grep -lir '\n* !^FROM_MAILER' .procmailrc | xargs sed -i 's/\n* !^FROM_MAILER//g'
But it is not replacing the *
. In leaves the line in with just the *
on it. If I escape the *
as follows, that also does not work:
grep -lir '\n\* !^FROM_MAILER' .procmailrc | xargs sed -i 's/\n\* !^FROM_MAILER//g'
So I trying to find out how to do the find and replace to remove the entire line with the *
in it.
sed
operates on lines of text, where a line of text is a sequence of characters between one newline and another (or before the first newline); therefore, you generally don't include\n
insed
commands. (There are some exceptions.) Your commands with\*
might have come close to working if you had left out the\n
. (Similarly, don't think in terms of deleting\n
characters; think in terms of deleting lines.)