Recent Changes - Search:




  • sed (stream editor) is a Unix utility that parses text.
  • Note: "sed -i" overwrites the original file with a new one.
$ sed -i 's/123/222/' p
  • -e option indicates that the sed expression follows:
sed -e 's/oldstuff/newstuff/g' inputFileName > outputFileName
  • The s stands for substitute. The g stands for global.
  • The d command to delete lines that are either blank or only contain spaces:
$ sed -e '/^ *$/d' p

Regular expression metacharacters:

    *The caret (^) matches the beginning of the line.
    *The dollar sign ($) matches the end of the line.
    *The asterisk (*) matches zero or more occurrences of the previous character.
  • To delete any line containing the word "yourword" from the file "yourfile":
sed '/yourword/d' yourfile
  • To delete all instances of the word "yourword":
sed 's/yourword//g' yourfile
  • To delete two words from a file simultaneously:
sed -e 's/firstword//g' -e 's/secondword//g' yourfile


sed  's/firstword//g;s/secondword//g' yourfile

Edit - History - Print - Recent Changes - Search
Page last modified on August 24, 2012, at 02:41 PM