sed 命令使用

使用參數:

Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
-c, --copy
use copy instead of rename when shuffling files in -i mode
(avoids change of input file ownership)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
--help display this help and exit
--version output version information and exit

If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.

將錯誤報告通過電子郵件發送到:[email protected] .
請務必將單詞“sed”放在“Subject:”域的某處。


添加行

sed -i 'aaaa' test.txt

發現所有的行都加上了aaaa

刪除行

sed -i '/aaaa/,+d' test.txt

刪除73和74行內容(源文件改變)

sed -i '73,74d' modules.conf

刪除73和74行內容(源文件不變)

sed '73,74d' modules.conf

在73行插入include "conf.d/proxy.conf"內容(源文件改變)

sed -i '73a include "conf.d/proxy.conf"' modules.conf

在73行插入include "conf.d/proxy.conf"內容(源文件不變)

sed -i '73a include "conf.d/proxy.conf"' modules.conf

替換指定行內容

sed -e '1,10s/enchantment/entrapment/g' myfile2.txt


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章