SED study notes

xiaoxiao2021-03-06  14

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: and other. Replace 1. Magic transformation (Y command Use) code: SED 'Y / Ori_Letter_List / Target_Letter_List /' FileName Code: CAT filename1234567890234567890170123 Testing files 1 replacement to a Plan 2 to b ... Put 0 in the file to j code: SED 'Y / 1234567890 / ABCDEFGHIJ / 'filenameABCDEFGHIJBCDEFGHIJACDEFGHIJABDEFGHIJABC conversion relationship is noted by the two positions corresponding to the list conversion, y is a command Authority refused to use the suffix flag / glist1: 1234567890list2: ABCDEFGHIJ again below the previous example as a reverse conversion codes: sed' y / 0987654321 / ABCDEFGHIJ / 'filenameJIHGFEDCBAIHGFEDCBAJHGFEDCBAJIGFEDCBAJIH2 replace each line of code match:. sed' s / regexpr / anyword / 'filenamesed' s / regexpr / anyword / 1 'filename example: reference: cat filename1234567890 23456789013456789012 4567890123sed' s / 5 / five / 'filename1234 five five 6789012 67890 234 567 890 134 45678901233. replace each row n (if any) matching Code: sed "s / regexpr / anyword / $ {n}" filenamecat filename111111111111111111222222222222222222333333333333333333444444444444444444 example sed "s / 4 / four / 8 "filename1111111111111111112222222222222222223333333333333333334444444 four 44444444444. Alternatively all matches each line of code: cat filename1234567890 23456789013456789012 4567890123 Code: example: sed ' s / 3 / three / g 'filename12 three three 45,678,901 45,678,902 456,789,012 456,789,012 thirty-two three line number 1. The process file number code plus the line:. sed = filename | sed' N; s // n /: / 'cat filename111111111111111111222222222222222222333333333333333333444444444444444444 example Code: sed = filename | sed 'N; s // n /: /' filename1: 1111111111111111112: 2222222222222222223: 3333333333333333334: 4444444444444444442 only text lines with their number code file: sed /./= a | sed '. /./N;s//n/:/ 'Code example: cat filename111111111111111111222222222222222222333333333333333333444444444444444444sed /./= a | sed' /./N;s//n/:/ 'filename1: 1111111111111111113: 2222222222222222224: 3333333333333333336: 444444444444444444 III. String flip code: SED '//n/ !s // (/ )/ (./n/ )/&/2/1/;

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;}'

转载请注明原文地址:https://www.9cbs.com/read-50775.html

New Post(0)