sed -n 5p file ##顯示第五行
sed -n 3,5p file ##顯示3到5行
sed -ne "3p;5p" file ##顯示3和5行
sed -ne 1,5p file ##1-5行
sed -ne '5,$p' file ##5到最後以行
sed -n '/^#/p' file ##顯示以#開頭的行
sed -n '/#$/p' file##顯示以#結尾的行
shell.2文本處理工具1.grep2.sed3.awk
d ##删除
sed 5d file ##删除第五行
sed '/^#/d' file ##把#開頭的行删除
sed '/^#/!d' file ##除了#開頭以外的行都删除
sed -e '5,$d' file##删除第五行以後的
a ##添加
sed -e '$a hello world' file##在最後一行添加hello world
sed -e '$a hello\nworld' file
sed -e '/^#/a hello world' file##在以#開頭的行後添加一行hello world
c ##替換
sed -e '/^#/c hello world' fstab##把以#開頭的行替換為hello world
sed '5c hello world' westos##把第五行替換為hello world
w ##把符合的行寫到指定檔案中
i ##插入
r ##整合檔案
sed '5r haha' file
sed 字元替換
sed 字元替換
sed 's/:/###/g' file #把全部冒号替換為###
sed 's/:/###/' file #把每行的第一個冒号替換成###
sed 's/:/###/2' file #把每行的第2個冒号替換成###
sed 's/:/###/g' file
sed '1,5s/:/###/g' file #把第一行和第五行的冒号替換成###
sed '1s/:/###/g' file #把第一行的冒号替換成###
sed '1s/:/###/g;5s/:/###/g' file #把第一行和第五行的冒号替換成###
sed '/lp/,/shutdown/s/:/###/g' file ## 把lp和shutdown之間得冒号全部替換為###
sed 's/\//####/g' file ##把/替換為###,\轉義字元
sed 's@/@####@g' file
sed 's@/@####@g' -i file 把sed處理的内容儲存到file檔案中