Tutorial by Examples

$ cat ip.txt address range substitution pattern sample Nth line $ sed -n '2p' ip.txt range $ sed '3d' ip.txt address range pattern sample Last line $ sed -n '$p' ip.txt sample
$ cat ip.txt address range substitution pattern sample Range specified is inclusive of those line numbers $ sed -n '2,4p' ip.txt range substitution pattern $ can be used to specify last line. Space can be used between address and command for clarity $ sed -n '3,$ s/[aeiou]/...
$ cat ip.txt address range substitution pattern sample Add Sub Mul Div Lines matching a pattern $ sed '/add/d' ip.txt range substitution pattern sample Add Sub Mul Div $ sed -n '/t/p' ip.txt substitution pattern $ sed -n '/[A-Z]/ s| |/|gp' ip.txt Add/Sub/Mul/Div ...
$ cat ip.txt address range substitution pattern sample Add Sub Mul Div Line number to line matching pattern $ sed -n '2,/pat/p' ip.txt range substitution pattern Line matching pattern to line number $ sed '/pat/,$d' ip.txt address range substitution GNU sed ...
$ cat ip.txt address range substitution 1234 search pattern sample Add Sub Mul Div Deleting lines other than address specified $ sed '/[0-9]/!d' ip.txt 1234 $ sed -n '/[0-9]/p' ip.txt 1234 $ sed '$!d' ip.txt Add Sub Mul Div $ sed -n '$p' ip.txt Add Sub Mul Div ...

Page 1 of 1