INPUT: Select ASDF 325 sdfg sdflk lkSelect TRG 46sdg rasdftz fsgs 45Select ASDF 6ffg sdfg 4456 sdrgOUTPUT: Select ASDF 325 XXXX sdflk lkSelect TRG 46sdg rasdftz fsgs 45Select ASDF 6ffg XXXX 4456 sdrgSo in short I need to sed sdfg to XXXX. BUT: only in lines that contains the Select ASDF string.. How can I do this? (sed, awk, etc. :\ )
How to sed only that lines that contains given string?
sed;awk
You can prefix most sed commands with an address to limit the lines to which they apply. An address can be a line number, or a regex delimited by /.cat INPUT | sed '/Select ASDF/ s=sdfg=XXXX='As mentioned Peter.O, the command as written above will substitute the first occurrence of any sdfg in the string containing Select ASDF. If you need to substitute the exact match to sdfg only in the case it is in fourth column you should go this way:cat INPUT | sed 's/\(^Select ASDF [^ ]* \)sdfg /\1XXXX /'