0

file:

sh  xyz/abc/www/def/gef/rqs/
sh xyz/toh/aaa/def/gef/rqs/
sh xyz/123/qqq/def/gef/rqs/

I want changes like this

sh  xyz/abc/www/def/gef/rqs/
#sh xyz/toh/aaa/def/gef/rqs/
sh xyz/123/qqq/def/gef/rqs/

edited: file paths to match my problem statement.

  • 1
    Based on what criteria, exactly? – steeldriver May 1 at 18:02
  • The line with xyz/toh/aaa should be commented – Tohid Tamboli May 1 at 18:04
1

You can use

sed -i '\%xyz/toh/aaa% s/^/#/' file

Explanation:

  • \% set the regex delimiter to % (so as not to conflict with the path separator /)
  • match xyz/toh/aaa
  • replace the start of line ^ by `#
  • Thanks you made my day, also i want to add, sed -i '\%'$file_path/$var'% s/^/#/' file if you need to use variables in it. – Tohid Tamboli May 1 at 18:13
0

And why not using vim?

vi -c 'g/xyz\/toh\/aaa/s/^/#/ | x' file

or

vi -c '%s!.* xyz/toh/aaa!#&! | x' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.