sed programs are rather short and simple. sed scripts can have comments (the line starting with the # symbol). The s (substitute) command is the most important sed command. sed allows simple programming, with commands such as q (quit). sed uses regular expressions, such as .* (zero or more of any character). Other simple examples Below follow various sed scripts; these can be executed by passing as an argument to sed, or put in a separate file and executed via -f or by making the script itself executable. To replace any instance of a certain word in a file with "REDACTED", such as an IRC password, and save the result: sed -i s/yourpassword/REDACTED/ ./status.chat.log To delete any line containing the word "yourword" (the address is '/yourword/'): /yourword/ d To delete all instances of the word "yourword": s/yourword//g To delete two words from a file simultaneously: s/firstword//g s/secondword//g To express the previous example on one line, such as when entering at the command line, one may join two commands via the semicolon: sed "s/firstword//g; s/secondword//g" inputFileName Multiline processing example In the next example, sed, which usually only works on one line, removes newlines from sentences where the second line starts with one space. Consider the following text: This is my dog, whose name is Frank. This is my fish, whose name is George. This is my goat, whose name is Adam. The sed script below will turn the text above into the following text. Note that the script affects only the input lines that start with a space: This is my dog, whose name is Frank. This is my fish, whose name is George. This is my goat, whose name is Adam. The script is: N s/\n / / P D This is explained as: (N) add the next line to the pattern space; (s/\n / /) find a new line followed by a space, replace with one space; (P) print the top line of the pattern space; (D) delete the top line from the pattern space and run the script again. This can be expressed on a single line via semicolons: sed '' inputFileName Limitations and alternatives While simple and limited, sed is sufficiently powerful for a large number of purposes. For more sophisticated processing, more powerful languages such as AWK or Perl are used instead. These are particularly used if transforming a line in a way more complicated than