Sunday, 14 December 2008

sed - grouping multiple instructions

Grouping two or more commands in sed using { } braces.

Exp : For example, if i want to remove all blank lines and # type comments in my shell script.

I can use sed -e 's/#.*//' -e '/^$/ d' . (using -e to write two or more commands at the same time)

without -e option the above version can be written as :

sed -n '
/^$/ d
}' > noblank.txt

The redirected noblank.txt file contains my lines w/o # type comments and blank lines.

No comments:

Post a Comment

Tweets by @sriramperumalla