http://sed.sourceforge.net/sed1line.txt
Popularity Report
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
URL Tag Cloud
Bookmark History
Saved by 23 people (-4 private), first by anonymouse user on 2006-07-21
- Abelmora on 2009-07-22 - Tags sed
- Canissirius on 2009-06-13 - Tags unix
- Archon810 on 2009-01-08 - Tags linux , tips , unix , sed , text
- Cermus on 2008-02-14 - Tags del.icio.us , imported , technology , tutorials
- Paulonuin on 2008-01-23 - Tags sed , linux , shell , programming
Public Sticky notes
# double space a file
sed G
Highlighted by diigo_llogin
# undo double-spacing (assumes even-numbered lines are always blank)
sed 'n;d'
# insert a blank line above every line which matches "regex"
sed '/regex/{x;p;x;}'
# insert a blank line below every line which matches "regex"
sed '/regex/G'
# insert a blank line above and below every line which matches "regex"
sed '/regex/{x;p;x;G;}'
Highlighted by diigo_llogin
numbers
Highlighted by drsnyder
# if a line ends with a backslash, append the next line to it
sed -e :a -e '/\\$/N; s/\\\n//; ta'
# if a line begins with an equal sign, append it to the previous line
# and replace the "=" with a single space
sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'
Highlighted by diigo_llogin
# print paragraph if it contains AAA (blank lines separate paragraphs)
# HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'
# print paragraph if it contains AAA and BBB and CCC (in any order)
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d'
# print paragraph if it contains AAA or BBB or CCC
sed -e '/./{H;$!d;}' -e 'x;/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
gsed '/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d' # GNU sed only
Highlighted by diigo_llogin
# print section of file from regular expression to end of file
sed -n '/regexp/,$p'
Highlighted by diigo_llogin
# print only lines of 65 characters or longer
sed -n '/^.\{65\}/p'
# print only lines of less than 65 characters
sed -n '/^.\{65\}/!p' # method 1, corresponds to above
sed '/^.\{65\}/d' # method 2, simpler syntax
Highlighted by diigo_llogin
# print section of file based on line numbers (lines 8-12, inclusive)
sed -n '8,12p' # method 1
sed '8,12!d' # method 2
Highlighted by diigo_llogin
# beginning at line 3, print every 7th line
gsed -n '3~7p' # GNU sed only
sed -n '3,${p;n;n;n;n;n;n;}' # other seds
Highlighted by diigo_llogin


Public Comment