Filtering and transforming texts via stream editing: SED

SED

SED processes the indicated lines in a file, and makes operations such as string substitution basing on the given parameters. The basic output is displayed, but you can write it into a file with ">" as usual.

sed s/pattern/replace_string/ file
Substitute first string occurrence in every line

sed s/pattern/replace_string/g file
Substitute all string occurrences in every line

sed 1,4s/pattern/replace_string/g file
Substitute all string occurrences in the range 1-4 of lines

sed -i s/pattern/replace_string/g file
Save changes for string substitution in the same file

To convert 01/02/… to SUN/MON/…
$ sed -e 's/01/SUN/'-e 's/02/MON/' -e 's/03/TUE/' -e 's/04/WED/' -e 's/05/THU/' -e 's/06/FRI/'  -e 's/07/SAT/'



Comments