1.sed replacing line breaks and label usage
echo "A,b,c,d" |sed ' s/,/\n/g ' |sed ' s/\n/,/g '
Parsing: The above command does not implement the replacement line character, which is related to the line processing of sed, sed read a line, will first take the line break, after processing and then add, so it is not possible to use the above command to replace the newline character, You must use the other commands in SED to complete. The above recovery can use the TR command:
echo "A,b,c,d" |sed ' s/,/\n/g ' |tr-t ' \ n ', '
The following command implements all line breaks in the replacement text:
Sed ': label; N;s/\n/:/;b label ' filenamesed ': label; N;s/\n/:/;t label ' filename
Analytical:
: label; This is a tag, used to implement the jump processing, the name can be arbitrarily taken (label), the following B label is the jump command
N n is a processing command for the SED, appending the next line in the text stream to the pattern space for merging, so that line breaks are visible
s/\n/:/; S is the Replace command for SED, replacing newline characters with colons
b label or T label b/t is an sed jump command that jumps to the specified label
2.sed output odd and even rows
A.
Sed-n ' p;n ' file #奇数行sed-n ' n;p ' file #偶数行
Parse: n means reading the next input row and processing the new row with the next command instead of the first command.
B.
Sed-n ' 1~2p ' file #奇数行sed-n ' 2~2p ' file #偶数行
Parse: The first number represents the starting line, and the second number represents the stride.
Resources:
http://my.oschina.net/shelllife/blog/118337
Examples of common usage techniques for SED