Sed

From Secure Computing Wiki
Revision as of 12:50, 13 February 2008 by 209.240.66.157 (Talk) (New page: * Find the first instance of '''foo''' and replace it with '''bar''' within a file <filename>. ''This is really good for multi-gigabyte files where you want to change something on the fir...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  • Find the first instance of foo and replace it with bar within a file <filename>. This is really good for multi-gigabyte files where you want to change something on the first line without loading the file into an editor.
sed -in "s/foo/bar/;q" <filename>
  • Find ALL instances of foo and replace it with bar within a file <filename>.
sed -in "s/foo/bar/g" <filename>
  • Find ALL instance of foo and replace it with bar within a file <filename>, and create a backup of the original file.
sed -i ".bak" -n "s/foo/bar/g <filename>