Hello, i have a directory with many files, each file contains various HTML and also several occurences of ".com/" and i want to replace .com/ by .com/# BUT replacement should happen only if the line where is .com located do NOT contains phrasse: -t Please how to do it via Linux command line? Thank you
You can likely do this with a mix of sed and regex (http://www.regular-expressions.info/lookaround.html).
One can try following (with caution and having backup): perl -i -pe 's/\.com\//$&#/ unless /-t/' *txt sed -e '/-t/! s:\.com/:.com/#:g' -i *.txt g means global, replace multiple occurences at one line sed -e '/-t/! s/\.com\//\.com\/#/' -i *.txt