标签:
$ echo "this is a test " | sed ‘s/test/big test/‘ this is a big test
$ cat test There are two dogs $ sed ‘s/dogs/cats/‘ test There are two cats
$ sed ‘s/dogs/cats/; s/two/three/‘ test There are two cats
$ cat script s/dogs/cats/ s/two/three/ $ sed -f script test
$ cat test There are two cats and two dogs There are two cats and two dogs $ sed ‘s/two/three/‘ test There are three cats and two dogs There are three cats and two dogs $ sed ‘s/two/three/2‘ test There are two cats and three dogs There are two cats and three dogs $ sed ‘s/two/three/g‘ test There are three cats and three dogs There are three cats and three dogs
$ sed ‘s/\/bin\/bash/\/bin\/csh/‘ /etc/passwd
$ sed ‘s!/bin/bash!/bin/csh!‘ /etc/passwd
$ cat test.sh var=cats sed ‘s/dogs/‘"$var"‘/‘ test
$ cat test There are two dogs There are two dogs There are two dogs There are two dogs $ sed ‘2s/dogs/cats/‘ test There are two dogs There are two cats There are two dogs There are two dogs $ sed ‘2,3s/dogs/cats/‘ test There are two dogs There are two cats There are two cats There are two dogs $ sed ‘2,$s/dogs/cats/‘ test There are two dogs There are two cats There are two cats There are two cats
$ cat test There are two dogs There are two cats There are two birds $ sed -n ‘/cats/s/two/three/p‘ test There are three cats
$ sed -e ‘2,${s/dogs/cats/; s/two/three/}‘ test
$ cat test the line num is 1 the line num is 2 the line num is 3 $ sed ‘2,$d‘ test the line num is 1 $ sed ‘/2/$d‘ test the line num is 1 the line num is 3
$ cat test the line num is 1 the line num is 2 the line num is 3 $ sed ‘2i\this is a test line‘ test the line num is 1 this is a test line the line num is 2 the line num is 3 $ sed ‘2a\this is a test line‘ test the line num is 1 the line num is 2 this is a test line the line num is 3
$ cat test the line num is 1 the line num is 2 the line num is 3 $ sed ‘y/12/45‘ test the line num is 4 the line num is 5 the line num is 3
标签:
原文地址:http://www.cnblogs.com/hancq/p/5278652.html