[nSLUG] sed question

Stephen Gregory nslug at kernelpanic.ca
Wed Dec 28 20:19:37 AST 2005

On Wed, Dec 28, 2005 at 07:16:27PM -0400, Herb wrote:

> couple of more complex ones. There are lines that have chunks that
> need removing while keeping other chunks.
> EMAIL: address at here remove these bits

try awk:

awk ' /^EMAIL:/ { print $1 " " $2 }' < infile > outfile

If you want to keep the other lines in the file that do no start with
"EMAIL" try:

awk ' /^EMAIL:/ { print $1 " " $2 }   !/^EMAIL/ { print }'

While sed is good I have found awk to be better. Most problems solved
with sed can be solved with awk just as easily. It is still good to
know sed syntax as the vi/vim ex mode (: mode) syntax is similar.



More information about the nSLUG mailing list