Sunday, July 9, 2017

How to replace a string in a file(s)?


Working with Files and strings in a file in Unix is what a beginner shell script learner wants to do after s/he learns the very basic commands via terminal. So I found this really really really important resource on unix.stackexchange.com which describes multiple operations on strings in files.
The link mentioned below answers following questions.
  • replace string foo with bar in all files in the current directory?
  • do the same recursively for sub directories?
  • replace only if the file name matches another string?
  • replace only if the string is found in a certain context?
  • replace if the string is on a certain line number?
  • replace multiple strings with the same replacement
  • replace multiple strings with different replacements



About Me

authorHello, my name is Jack Sparrow. I'm a 50 year old self-employed Pirate from the Caribbean.
Learn More →