sed - stream editor for filtering and transforming text
sed
是十分强大和小巧的文本流编辑器。sed
是很有用(但常被遗忘)的UNIX
流编辑器。在以批处理方式编辑文件或以有效方式创建shell
脚本来修改现有文件方面,它是十分理想的工具。
/pattern/
shell> sed -e 'd' /etc/services
shell> sed -e '1d' /etc/services | more
shell> sed -e '1,10d' /etc/services | more
shell> sed -e '/^#/d' /etc/services | more
shell> sed -e '/regexp/d' /path/to/my/test/file | more
shell> sed -n -e '/regexp/p' /path/to/my/test/file | more
shell> sed -n -e '/BEGIN/,/END/p' /my/test/file | more
shell> sed -e 's/$/\r/' myunix.txt > mydos.txt
shell> sed -e 's/foo/bar/' myfile.txt
shell> sed -e 's/foo/bar/g' myfile.txt
shell> sed -e '1,10s/enchantment/entrapment/g' myfile2.txt
shell> sed -e 's:/usr/local:/usr:g' mylist.txt
shell> sed -e 's/<[^>]*>//g' myfile.html
shell> sed -i 's/regexp/replacement/g' myfile.txt
shell> sed -n '5,10p' myfile.txt
shell> sed -i -e 's/regexp/replacement/g' -e 's/str/newstr/' -e '/re/d' myfile.txt
shell> sed -n -f mycommands.sed myfile.txt
shell> cat oldfile | sed -e "s/testpattern/$REPL/g" > newfile
mycommands.sed
1,20{
s/[Ll]inux/GNU\/Linux/g
s/samba/Samba/g
s/posix/POSIX/g
}