Benutzer:Andreas Plank/Sed: Unterschied zwischen den Versionen
Aus Offene Naturführer
K |
K |
||
Zeile 14: | Zeile 14: | ||
# a → append action (after) | # a → append action (after) | ||
# $a append after last line | # $a append after last line | ||
− | # c → You can replace the current line with the ‘c’ action | + | # c → change: You can replace the current line with the ‘c’ action |
# d → delete action | # d → delete action | ||
# i → insert action (before) | # i → insert action (before) |
Version vom 27. November 2010, 00:35 Uhr
Text snippets for the sed running under Linux.
#### file options
# -e execute
# -f file: script file
# -i insert into file: edit file in place
# -l 40 specify the desired line-wrap length for the “l” command
# -n nothing i.e. quiet
# -r extended regular expressions
# -s separate: consider files as separate
# -u unbuffered
#### actions
# a → append action (after)
# $a append after last line
# c → change: You can replace the current line with the ‘c’ action
# d → delete action
# i → insert action (before)
# 1i insert before 1st line
# n → ?read the next line
# p → print action
# q → quit immediately without further processing
#### ACTIONS
# D → delete up to the first embedded newline in the pattern space
# N → ?append the next line
#### addresses for instance with p → print
'1,10p' # line 1 to 10
'/beginRE/,/endRE/p' # reg. expr: beginRE to endRE
'10~2p' # at line 10 then each 2nd line
'$=' # last line “$” and provide “=” the line
#### examples
# sorted lines → delete duplicate lines
sed '$!N; /^\(.*\)\n\1$/!P; D' temp2.txt > temp3.txt
# delete:
sed -e '1,10d' # line 1-10
sed -e '11,$d' # line 11 to end of file
sed -e '10~2d' # delete every 2nd line starting from 10
# extract:
sed -n -e '1,10p'
# quit
sed -e '10q' # quit
# commands on multiple lines or with -e again:
sed -e '1,4d
6,9d'
sed -e '1,4d' -e '6,9d'
# delete lines with debug + print lines with foo
sed -n -e '/debug/d' -e '/foo/p'
# pipes
gcc sourcefile.c 2>&1 | sed -n -e '/warning:/,/error:/p'