Skrevet av Emne: Fast search & replace using sed  (Lest 4268 ganger)

ATC

  • Gjest
Fast search & replace using sed
« på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • How to perform a search and replace on multiple files in Linux?



    ATC

    • Gjest
    [Solved] Fast search & replace using sed
    « Svar #1 på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • Use the "sed" command with a regular expression. For example, let's say you have a whole bunch of .css files where you need to replace every occurrance of the word "serif" with "sans-serif". Type the following:

    "sed s/serif/sans\-serif/ *.css"

    This command will read all the input files, apply the regex and print the output stream to the console. Now review the change to see if your regular expression worked as expected.

    If you're satisfied, execute "sed" again, but this time with the -i option. This option makes sed actually write the modified stream back to each input file:

    "sed -i s/serif/sans\-serif/ *.css"

    For more advanced use of sed, please refer to the man page.