
$ cat sample.crt | sed -ne '/-BEGIN/,/-END/p' Regular pattern $ cat sample.crt | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' Get first matching patten ( for CERTIFICATE ) * imarslo : get lines between 2 matched patterns.delete all comment lines : $ sed '/^#/ d' /path/to/file.delete all empty lines: $ sed '/^$/ d' /path/to/file.delete between 1 and 4 lines : $ sed '1,4 d' /path/to/file.delete the 2nd line : $ sed '2 d' /path/to/file.find pattern to the end : $ sed -n '/Raj/,$ p' employee.txtįind pattern and line after the matches line : $ sed -n '/Raj/, +1 p' employee.txtįind pattern to 4th line : $ sed -n '/Raj/,4 p' employee.txtįind pattern until find another pattern ( Jason to Anand ) : $ sed -n '/Jason/,/Anand/p' employee.txt.+ ( n, +m ) : sed -n 'n,+m p' employee.txt print only odd numbered lines : sed -n '1~2 p' employee.txt.print all lines since the 2nd line: $ sed -n '2,$ p' employee.txt.print 1~4 lines : $ sed -n '1,4 p' employee.txt.print the 2nd line : $ sed -n '2 p' employee.txt.print all lines : $ sed -n 'p' employee.txt.print every line twice $ sed 'p' employee.txt.Tasks: 853 total, 1 running, 448 sleeping, 0 stopped, 36 zombie between pattern_1 to pattern_2 : /pattern_1/,/pattern_2/.Tasks: 857 total, 2 running, 448 sleeping, 0 stopped, 36 zombie Tasks: 856 total, 2 running, 447 sleeping, 0 stopped, 36 zombie


Use sed to insert text before two blank lines.Delete unknown number of lines from * until blank line.Grep starting from a fixed text, until the first blank line.Remove empty line before a pattern using sed.Remove everything before a blank line using sed.: $ sed -n -e '/^root/p /^nobody/p' /etc/passwd Root:*:0:0:System Administrator:/var/root:/bin/sh Nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false get first matching patten ( for CERTIFICATE )Īppend the editing commands specified by the command argument to the list of commands.Įxample : show only root and nobody in /etc/passwd.example : show only root and nobody in /etc/passwd.
