Reputation: 25
I want to add specific string at the end on each line that has some Strings and the blank line should stay unaffected. How can I use the sed command so that the string i require is appened after only selected lines.
Say file name be temp.txt
abc "123.cf"
abc
abc "456.cf"
ksh
entry "e123.cf"
Now i want to append > /dev/null 2>&1 &
to the end of each line that has .cf" in the end
and need the result to be
abc "123.cf" > /dev/null 2>&1 &
abc
abc "456.cf" > /dev/null 2>&1 &
ksh
entry "e123.cf" > /dev/null 2>&1 &
I'm using the command:
sed -e 's:.cf"$:.ccf" > /dev/null 2>&1 &:' -i temp.txt
Does'nt seem to work. :-( Please help.
Upvotes: 0
Views: 242
Reputation: 41456
A variation of Glenns post:
awk '/.cf"$/ {$0=$0FS"> /dev/null 2>&1 &"}8' file
Upvotes: 0
Reputation: 195089
kent$ sed 's#.cf"$#& > /dev/null 2>\&1 \&#' file
abc "123.cf" > /dev/null 2>&1 &
abc
abc "456.cf" > /dev/null 2>&1 &
ksh
entry "e123.cf" > /dev/null 2>&1 &
it worked in bash.
Upvotes: 1