sed用法
2021/8/15 6:06:43
本文主要是介绍sed用法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
sed 用法
/ /开启匹配模式
a
sed '1,3a\hello world' 1.txt 1-3行追加hello
sed '/3/a\hello' 1.txt 匹配3追加hello
i
sed '1i\hello' 1.txt 第一行前插入
sed '/3/i\hello' 1.txt 匹配插入
d
sed '1d' 1.txt
sed '/3/d' 1.txt
sed -r '/^#|#|^$/d' my.cnf -r 正则 删除以#开头,包含,以空格开头的
s 替换
sed 's/cat/dog/' 1.txt
sed '2,4s/cat/dog/' 1.txt
sed '/3 the/s/cat/dog/' 1.txt 匹配的那行换掉
c 改
sed 'c\hello' 1.txt 默认全改
sed '2,4c\hello' 1.txt 把2-4删了 改为hello
sed '/3 the/c\hello' 1.txt 匹配改
y 转换
sed 'y/cat/TCA/' 1.txt
sed 'p' 1.txt 会打印两遍
flag: 2,g,w
sed 's/dog/cat/2' file
sed 's/dog/cat/g' file 全部替换
sed -n '3s/dog/cat/p' file 不会打印文本内容,只会打印改的 -n抑制内存输出 -p打印
sed -i '/dog/cat/g' file -i 修改原文件,不可逆
sed -i.bak '/dog/cat/g' file -i .bak可以修改前创建备份
sed -n '$=' file 打印多少行
这篇关于sed用法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-05小米13T Pro系统合集:性能与摄影的极致融合,值得你升级的系统ROM
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南