perl - If a line starts with a specific word, how to change a targeted word in that line if it does exist? -
looking search through files in directory, looking @ every line , if line starts word such "this
", search line find , replace targeted word. did solution being 1 line command, looking have perl file or .txt file using bash if possible.
example:
this rabbit jumped high rabbit jumped high
(find , replace high low if line starts "this:
this rabbit jumped low rabbit jumped high
sed '/^this/{s/high/low/g}' file
will you:
kent$ echo "this rabbit jumped high rabbit jumped high"|sed '/^this/{s/high/low/g}' rabbit jumped low rabbit jumped high
if want replace word "high" instead of text high:
sed '/^this/{s/\<high\>/low/g}' file
for example:
kent$ echo "this rabbit jumped high highfoo rabbit jumped high"|sed '/^this/{s/\<high\>/low/g}' rabbit jumped low highfoo rabbit jumped high
Comments
Post a Comment