Srilatha Marru's Blog
String replace in a file in unix using sed
  • sed reads from a file or from its standard input, and outputs to its standard output. You will generally want to redirect that into a file. sed does not get along with non-text files, like executables and FrameMaker files. If you need to edit those, use a binary editor like hexl-mode in emacs.

Example > sed   ‘s/fubar/foobar/’   filename  > newfilename

  • The single quotes protect almost everything from the shell. In csh or tcsh, you still have to watch out for exclamation marks, but other than that, you’re safe.
  • The GNU version of sed generally has better error messages:
    	gsed 's/fubar/foobar' filename
    	gsed: Unterminated `s' command
    

    So, if you’re having problems getting sed syntax correct, switch to gsed for a while.

More can be found at http://www.cs.hmc.edu/tech_docs/qref/sed.html#regexp  and

http://kb.iu.edu/data/afrk.html



AUTHOR

profileWeb Developer working in advertising agency.

Recent tweets

The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.