tags:

views:

34

answers:

2

hi

the following syntax target is to add "_name4" on the first string in line that match the "name1 + name2 + name3" and to replace old word with new

cat  file | sed  '/name1 + name2 + name3/s/[^ ]*\>/&_name4/'  | sed s'/old/new/g' > new_file

my question : is it possible to do the same without using cat command?

+4  A: 

You rarely need cat. You could do it like this:

sed '/name1 + name2 + name3/s/[^ ]*\>/&_name4/' file | sed 's/old/new/g' > new_file

You can also combine the sed commands:

sed '/name1 + name2 + name3/s/[^ ]*\>/&_name4/;s/old/new/g' file > new_file
Mark Byers
+1  A: 

sed file -e <expr> or sed <expr> file

Noel M