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' myscript.sh . (using -e to write two or more commands at the same time)

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

sed -n '
{
s/#.*//
/^$/ d
p
}' test.sh > noblank.txt

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

No comments:

Post a Comment

Tweets by @sriramperumalla