简体   繁体   中英

sed + without cat command

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM