replace - Comment out one line of many files with sed -


i need comment out line of many files on 1 path. line reads

input_types = ['text'] 

and need replace

#input_types = ['text'] 

i want like

sed -i 's/input_types/#input_types/g' path/to/files/* 

but change instances of input_types , don't want that.

i tried

sed -i 's/input_types = ['text']/#input_types = ['text']/g' path/to/files/* 

but didn't work

how can change specific instance?

you last try quite good, 2 things have changed:

  • you use single quotes enclose expression, single quotes part of expression -- gets confusing. in case it's better use double quotes enclosing expression, instead.
  • the [ ] brackets have escaped backslashes: \[ \]

so, if change line to

sed -i "s/input_types = \['text'\]/#input_types = \['text'\]/g" /path/to/files/* 

it should work.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -