Monday, 15 August 2011

Linux bash: how to replace 2 words in a file from bash command line -



Linux bash: how to replace 2 words in a file from bash command line -

this question has reply here:

simple find , replace sed 3 answers

i need replace 2 words in file bash command line, example: filea.txt

xxxx aa bb xxx

i need replace "aa bb" bash command line "cc dd", file become:

xxxx cc dd xxx

thanks help!

you seek below sed command,

sed -i 's/aa bb/cc dd/g' file

example:

$ echo 'xxxx aa bb xxx' | sed 's/aa bb/cc dd/g' xxxx cc dd xxx

and through awk,

awk '{sub(/aa bb/,"cc dd")}1' infile > outfile

example:

$ echo 'xxxx aa bb xxx' | awk '{sub(/aa bb/,"cc dd")}1' xxxx cc dd xxx

linux bash awk sed

No comments:

Post a Comment