0

I have a file containing my source code for a project I'm working on at the moment.

I have the word resolution scattered over the file, and want to prefix it with self.

--snippet--

resolution = readString[:16]
resolution = resolution.replace("\"", "")

--snippet--

How can I do this?

Python, sed, grep, awk, anything...

1
  • In Idle, simply use Ctrl+H Jan 27, 2016 at 21:54

2 Answers 2

1

Using sed:

sed -i 's/resolution/self.&/g' some/file

Though perhaps you should start using an IDE and its refactoring tools.

If resolution could be part of word (say you had resolutionFoo), use word boundary markers:

sed -i 's/\bresolution\b/self.&/g' some/file
1

You can use Vim in Ex mode:

ex -sc '%s/resolution/self.&/g|x' file
  1. % select all lines

  2. s substitute

  3. g replace all instances in each line

  4. x save and close

You must log in to answer this question.

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