GNU Sed Cheat Sheet: Sed - Options (Optional SCRIPT) (INPUT STREAM)
GNU Sed Cheat Sheet: Sed - Options (Optional SCRIPT) (INPUT STREAM)
GNU Sed Cheat Sheet: Sed - Options (Optional SCRIPT) (INPUT STREAM)
Sed is a stream editor. It transforms text in an input stream (a file or pipe). Sed works on one line at a
time, creating a pattern space; once pattern space is populated, transformations are performed.
Options
Address
sed -n '1q;p' Select line 1, and then print delete sed '1 d'
sed -n '1p;$p' Select first and last lines, and print delete sed '1d;$d'
sed '1!p' Select all but the first line, and print delete sed '1!d'
sed '/foo/ p' Select lines containing foo, then print delete sed '/foo/ d'
sed '3,7 p' Starting on line 3 and ending on line 7, print each line
sed '3,/foo/ p' Starting on line 3, ending after the first occurrence of foo, print each line
sed '/code/ s/closed/open/g' Replace closed with open on lines containing code
sed -n -e '/[Oo]pen/h' \ Copy and delete (effectively cut), and then paste any
-e '/[Oo]pen/d' \ line containing Open or open after the line containing
projects
-e '/projects/ G;p'
sed 's/^[ \t]*//' Remove leading spaces and tabs from line
Regular expression