Replacing/Removing Whole Lines
You can replace or remove whole lines in several ways. The next sections examine these in more detail.
Replacing Whole Lines
To completely replace any line that contains a pattern, you can use the sed command, like this:
sed 's/.*acme.*/ ***canceled*** /'
acme | This represents the pattern to look for. You can replace this with any desired R.E. pattern. |
.*acme.* | This matches the whole line that contains acme, so the whole line will be replaced. |
Removing Lines Containing a Regular Expression Pattern
To totally remove any lines containing a pattern, use the –v option to grep, as follows:
grep -v 'R.E.'
The –v option to grep reverses the sense of grep. Instead of showing lines that contain the pattern, grep will then ...
Get Practical UNIX now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.