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.

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

2 Answers 2

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 `#
1
  • 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. May 1, 2019 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .