This page refers to sed, the non-interactive text file editor.

Sex shares a similar invocation syntax of awk and both use regular expressions , both read input by default from stdin, and both output to stdout.

sed

It receives text input, whether from stdin or from a file, performs certain operations on specified lines of the input, one line at a time, then outputs the result to stdout or to a file.

Sed determines which lines of its input that it will operate on from the address range passed to it. The address range can be either a line number or a pattern to match (e.g. 3d → delete line 3 , /windows/d → every line of the input containing a match to “windows” deleted).

The three more common uses of sed is for printing (to stdout), deletion, and substitution.

Operator Name Effect
[address-range]/p print Print [specified address range]
[address-range]/d delete Delete [specified address range]
s/pattern1/pattern2/ substitute Substitute pattern2 for first instance of pattern1 in a line
[address-range]/s/pattern1/pattern2/ substitute Substitute pattern2 for first instance of pattern1 in a line, over address-range
[address-range]/y/pattern1/pattern2/ transform replace any character in pattern1 with the corresponding character in pattern2, over address-range (equivalent of tr)
g global Operate on every pattern match within each matched line of input

Examples:

  sed -n '/fo[r]/p' teste.log

The -n option tells sed to print only those lines matching the pattern.

  sed 's/Missing/Not Missing/' teste.log

References: