$ Cat test.txt line1line2line3line4
$ Sed-I '/line/{n; d}' test.txt $ cat test.txt line1line2line3line4
$ Sed-I '/line1/{n; d}' test.txt suzhaoqiang @ suzhaoqiang-OptiPlex-380 :~ /Android/source/linux_learned $ cat test.txt line1line2line3line4
$ Cat test.txt line1line2line3line4line5
$ Sed-I '/line1/{N; s/\ n //}' test.txt $ cat test.txt line1 line2line3line4line5
$ Sed-I '{N; s/\ n //}' test.txt
$ Cat test.txt line1line2line3line4line5 $ sed 'n';/line3/d' test.txt line1line2line5
$ Sed 'n';/line3/d' test.txt line1line2line4line5
$ Cat test.txt line1line2line3line4line5 $ sed-n 'n';/line/P' test.txt line1line2line3line4 $ sed-n' N;/line/P' test.txt line1line3
$ Cat test.txt line1line2line3line4line5line6 $ sed-n '/line1/{h; p; n; p; g; p} 'test.txt line1line2line1
$ Sed-n '1 {h; N; G; p} 'test.txt line1line2line1
Man wrote After the address (or address-range), and before the command,! May be inserted, which specifies that the command shall only be executed if the address (or
Address-range) does not match.
$ Cat test.txt line1line2line3line4line5line6 $ sed-n'/[1-3]/! P'test.txt line4line5line6
$ Sed-n' 1! G; h; $ p 'test.txt line6line5line4line3line2line1 $ tac test.txt line6line5line4line3line2line1
$ Tac test.txt line6line5line4line3line2line1
]B[Label]
$ Sed '2, 3b; s/line/Line/; s/Line/lines/'test.txt lines1line2line3lines4lines5lines6
$ Sed-n'1b test; G;: test h; $ p 'test.txt line6line5line4line3line2line1
$ Echo "This, is, a, test, to, remove, commas. "| sed-n' {: start; s/, // p; B start} 'This is, a, test, to, remove, commas. this is a, test, to, remove, commas. this is a test, to, remove, commas. this is a test to, remove, commas. this is a test to remove, commas. this is a test to remove commas.
$ Echo "This, is, a, test, to, remove, commas. "| sed-n' {: start; s/, // p;/,/B start} 'This is, a, test, to, remove, commas. this is a, test, to, remove, commas. this is a test, to, remove, commas. this is a test to, remove, commas. this is a test to remove, commas. this is a test to remove commas.
$ Echo "This, is, a, test, to, remove, commas. "| sed-n' {: start; s/, //;/,/B start; p} 'This is a test to remove commas.
$ Cat test.txt line1line2line3line4line5line6 $ sed's/line [45]/Line/; t; s/line [0-9]/line/'test.txt linelinelinelinelinelineline
$ Echo "This, is, a, test, to, remove, commas. "| sed-n' {: start; s/, //; t start; p} 'This is a test to remove commas.
$ Cat test.txt line1line2line3line4line5line6 $ sed's/[0-9]/0 &/'test.txt line01line02line03line04line05line06
$ Sed's/\ ([0-9] \)/0 \ 1/'test.txt line01line02line03line04line05line06
$ Echo "1234567" | sed ': start; s /\(. * [0-9] \) \ ([0-9] \ {3 \} \)/\ 1, \ 2 /; t start '1970 $ echo "1,234,567" | sed ': start; s /\(. * [0-9] \) \ ([0-9] \ {3 \} \)/\ 1, \ 2 /; t start '1970 $ echo "12,345,678" | sed ': start; s /\(. * [0-9] \) \ ([0-9] \ {3 \} \)/\ 1, \ 2/; t start' 123,456,789
String reg1 = "\ d (? = (\ D {3}) + $) "; System. out. println ("123456789 ". replaceAll (reg1, "$0,"); System. out. println ("12345678 ". replaceAll (reg1, "$0,"); System. out. println ("1234567 ". replaceAll (reg1, "$0 ,"));
$ Cat sed_test #! /Bin/bashsed-n' 1! G; h; $ P' "$1"
$ Cat test.txt line1line2line3line4line5line6 $ sed_test test.txt line6line5line4line3line2line1
$ Cat test.txt line1line2line3 $ sed '$! G'test.txt line1line2line3
$ Sed '/^ $/d; $! G'test.txt
$ Cat test.txt line1line2line3 $ sed '= 'test.txt | sed 'n'; s // \ N // '1 line12 line23 line3
$ Sed-n' $ P' test.txt
$ Cat test.txt line1line2line3line4line5line6line7line8line9 $ sed ': start; $ q; N; 4, $ D; B start 'test.txt line7line8line9
$ Sed ': start; $ q; N; 1, 4D; B start 'test.txt line4line5line6line7line8line9
$ Sed '/./,/^ $ /! D 'test.txt
$ Sed '/./, $! D 'test.txt
$ Sed '{>: start>/^ \ n * $/{$ d; N; B start }>} 'test.txt
, We cannot use all .*?In this form, of course, the following straightforward greedy model is certainly wrong.
$ Sed's/<. *> // G' test.html
We simply simulate the inertia matching:
$ sed 's/<[^>]*>//g' test.html
Finally, if you want to delete empty rows, you can add the following:
$ sed 's/<[^>]*>//g;/^$/d' test.html