Está en la página 1de 2

Sed Cheat Sheet Sed command line options Sed syntax: sed [options] sed-command [input-file] -n -i -f -e Suppress default

pattern space printing Backup and modify input file directly Execute sed script file Execute multiple sed commands

www.thegeekstuff.com

sed -n '3 p' employee.txt sed -ibak 's/John/Johnny/' employee.txt sed -f script.sed employee.txt sed -e 'command1' -e 'command2' input-file

Sed substitute command and flags Syntax: sed 's/ori inal-strin /replacement-strin /[fla s]' [input-file] g flag 1,2.. flag p flag " flag i flag e flag %&'() * ,- ,. ,1 ,2 ,/ Global substitution Substitute t e nt occurrence !rint only t e substituted line #rite only t e substituted line to a file $gnore case " ile searc ing Substitute and execute in t e command line Substitution delimiter can be any c aracter Gets t e matc ed pattern. +se t is in replacement string. sed 's/!indo"s/#inux/ ' "orld.txt sed 's/locate/find/2' locate.txt sed -n 's/John/Johnny/p' employee.txt sed -n 's/John/Johnny/" output.txt' employee.txt sed 's/$ohn/Johnny/i' employee.txt sed 's/%/ls -l /' files.txt sed 's&/usr/local/bin&/usr/bin&' path.txt sed 's/%.'/()*/' employee.txt +,ncloses "hole line bet"een ( and *

Group using ,- and ,.. +se ,1, ,2 in sed 's/-.[%/]'-0/-.[%/]'-0/-.[%/]'-0.'/-1/-3/ ' replacement string to refer t e group. employee.txt +1et only 1st and 3rd column

Sed commands p d " a !rint pattern space 0elete lines #rite pattern space to file 1ppend line after sed -n '1/2 p' employee.txt sed -n '1/2 d' employee.txt sed -n '1/2 " output.txt' employee.txt sed '2 a ne"-line' employee.txt

Sed and Awk 101 Hacks Enhance your UNIX / !nu" !fe w!th Sed and Awk

Sed Cheat Sheet i c l 3 y 4 r 7 $nsert line before 2 ange line !rint idden c aracters !rint line numbers 2 ange case 5uit sed 6ead from file 2omment inside sed script

www.thegeekstuff.com sed '2 i ne"-line' employee.txt sed '2 c ne"-line' employee.txt sed -n l employee.txt sed 3 employee.txt 4 sed '567s/-n/ /8' sed 'y/abcde/9:;<,/' employee.txt sed '3 =' employee.txt sed '> r lo .txt' employee.txt

Sed hold and pattern space commands n x !rint pattern space, empty pattern space, and read next line. S"ap pattern space "it old space

2opy pattern space to old space 8 g G 1ppend pattern space to old space 2opy old space to pattern space 1ppend old space to pattern space

Loops and multi-line sed commands b label t label :label : ! 0 Branc to a label -for looping. Branc to a label only on successful substitution -for looping. 9abel for t e b and t commands -for looping. 1ppend next line to pattern space !rint 1st line in multi-line 0elete 1st line in multi-line

Sed and Awk 101 Hacks Enhance your UNIX / !nu" !fe w!th Sed and Awk

También podría gustarte