曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 2846|回复: 0
打印 上一主题 下一主题

-i 选项 -- 将改变写入文件

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2012-1-3 14:09:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一般情况下,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
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-3 23:17 , Processed in 0.086176 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表