perl - If a sentence starts with a specific word, how to change a word in that sentence if it does exist? -


so, searching lines in .txt file , if starts word such "this", how swap targeted word in sentence if exist? open doing bash, perl or awk.

perl -pi -e "s/^this\b/that/" myfile 

or, if want change different word within line,

perl -pi -e "s/\btargeted\b/swap/ if /^this\b/" myfile 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -