15 sed stream editor Flashcards
sed scripts can be provided on the command line
sed [-e] ‘command’ files
All commands are applied in sequence to each line
sed scripts can be provided in a separate file
sed -f scriptfile files
General form of a sed command:
[address[,address]][!]command[arguments]
Addresses
Addresses can be line numbers or regular expressions.
Last line
Last line is “$”.
Line range
One address selects a line, two addresses a line range (specifying start and end line).
Optionally print
After this, the line is printed, unless option -n is used, in which case only the p command will print a line.
Negate address matches
The ! negates address match. {. . . } can group commands per address.
Regex enclosed in
Regular expressions enclosed in /. . . /. Some regular expression meta characters:
matches any character (except new-line)
“.”
matches the preceding item zero or more times
“*”
matches the preceding item one or more times
“+”
matches the preceding item optionally (0–1 times)
“?”
matches start of line
“^”
matches end of line
“$”