Disclaimer: These codes are just to learn and understand the SED commands. It does not represent the unique solution or best solution of the problem. I hope that all bricks reference materials:
S /.// 'Example code: ECHO 1234567890 | SED' //n/ !g; / (./ )/ (./N/ )/&/2/1/;s/.// ' 0987654321 IV. Selective output 1. Print document odd line (interlaced output) code: SED 'N; d'sed' x; $! N; x'sed -n 'p; n'13572. Print even digital line (interlaced) ) Code: SED -N 'N; p'sed' 1d; n; d; '24683. Delete continuous repetition (pay attention to the Pattern Space file too much) Code: Sed' $! N; / ^ / (. * /)! / n / 1 $ / P; D '# $ N to be careful using the memory overflow example Code:! cat file111111111111111111222222222222222222222222222222222222333333333333333333444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444sed'! $ N; /^/(.*/)/n/1$/! P; D 'filename1111111111111111112222222222222222223333333333333333334444444444444444444 combined with vertical rows separated by spaces Code:. sed'! $ N; s // n / / 'Code example: after Run will 09876543215. 1234567890 / downlink combined symbol row ending cat file12345678900987654321 separated by spaces (splice line breaks) Code: sed -e: a -e '/// $ / N; sn / /; ta' Code example: cat filename1 111111111111111111/2 2222222222222222223 333333333333333333/4 444444444444444444sed -e: a -e '/// $ / N; Sn / /; ta' filename1 11111111111111112222222222222222223 3333333333333333 333333333333333 33333333333333344446. Press keyword splicing row If a line is started, merge into the previous row and replacing = space code: SED -E: A -E '$! n; s // n = / /; ta '-E' P; D 'Code Example: cat file111111111111111111222222222222222222 = 333333333333333333444444444444444444sed -e: a -e' $ N; s // n = / /; ta '-e' P; D 'filename111111111111111111222222222222222222 3333333333333333334444444444444444447. output matching line! the next line of code: sed -n '/ regexpr / {n; p;}' filename Code example: cat filename1 1111111111111111112 2222222222222222223 3333333333333333334 444444444444444444sed -n '/ ^ 3 / {n; p;}' filename4 4444444444444444448. display line matching lines Number and output matching row uplink, matching line, down, sed -n -e '/ regexpr / {=; x; 1! P; g; $! N; p; d;}'