曲径通幽论坛

标题: -i 选项 -- 将改变写入文件 [打印本页]

作者: beyes    时间: 2012-1-3 14:09
标题: -i 选项 -- 将改变写入文件
一般情况下,sed 不会改变源文件,但如果使用了 -i 选项,那么替换等效果就会写到源文件里了,但是同时给出后缀,那么源文件会被备份到一个以此后缀结尾的文件中。

示例:
$ cat hello.txt
hello linux shell world
$sed -i 's/linux/LINUX/g' hello.txt
$ cat hello.txt
hello LINUX shell world

在写入文件时生成一个备份文件:
$ sed -i.bak 's/LINUX/linux/g' hello.txt
$ ls
hello.txt  hello.txt.bak
$ cat hello.txt
hello linux shell world
$ cat hello.txt.bak
hello LINUX shell world





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2