Sed Find and Replace

by Vince
in Blog
Hits: 1874

While hunting through 15,000 lines of CSS, I wanted to find and replace some text.  I thought it was going to be a simple task but there were numerous references and using 'find next' was getting tedious.  I dropped to a command line and used sed to complete the task.  Sed is a stream editor and the syntax is simple:

sed -i 's/old/new/g' myfile.css

-i = saves the changes back to the original
s = issues the substitution
old = for what you're replacing
new = for what you want it to be when all is said and done
g = issues a replace all
myfile.css = the file you want to do the finding and replacing