Linux中的shell命令sed的介绍

shell脚本中的sed -i的作用,以及sed的使用

再shell脚本中经常看到sed的使用:

 

新建文件test.txt,并输入内容:

 

然后执行:sudo sed -i "s/abcde/12345/g" ./test.txt

 

再次查看test.txt

 

可以看出,sed -i的作用就是使用后面的字符串全局替换前面的字符串。


sed的参数说明:

xuyw@zlx123:/home/work/xuyw/src/test$ sed

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

 

  -n, --quiet, --silent

                 suppress automatic printing of pattern space

  -e script, --expression=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

  --follow-symlinks

                 follow symlinks when processing in place

  -i[SUFFIX], --in-place[=SUFFIX]

                 edit files in place (makes backup if SUFFIX supplied)

  -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

  -z, --null-data

                 separate lines by NUL characters

      --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.

 

GNU sed home page: <http://www.gnu.org/software/sed/>.

General help using GNU software: <http://www.gnu.org/gethelp/>.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值