20190135sed

###补充

^.*$ 整行

sed

在这里插入图片描述
sed [-nefri] [动作]
-n:只列出经过sed特殊处理过的行
-e:可以在同一行里执行多条命令
-f:将sed的动作写入一个文件内,
== -r:支持扩展型正则表达式的语法(可以不脱义使用?,+,|,(),类似于grep -E==
-i:直接修改读取的文件内容,而不是有屏幕输出

sed -n ‘5’p test.txt 不加-n会打印所有的内容,并把匹配行输出2次。
==sed 中使用外部变量,可以把单引号换成双引号 sed -i =="&s/./IPADDR= i p a d d r / " s e d − n ′ 1 , 5 ′ p t e s t . t x t s e d − n ′ 1 , ipaddr/" sed -n '1,5'p test.txt sed -n '1, ipaddr/"sedn1,5ptest.txtsedn1,'p test.txt ==$表示尾行
sed -n '/root/'p test.txt
sed -n '/^1/'p test.txt
sed -n ‘inKaTeX parse error: Expected 'EOF', got '#' at position 200: …est.txt sed 's#̲ot#to#g' test.t…/123&/’ test.txt
sed -i ‘s/ot/to/g’ test.txt
替换:sed ‘1,10s/nologdin/login/g’ 1.txt (g全局替换)
sed ‘s#^.
KaTeX parse error: Expected 'EOF', got '#' at position 1: #̲&login#g' 1.txt…/123&/’ test.txt 在每一行的前面加上123
sed 's#[^0-9a-zA-Z]##g’ 1.txt 把非数字字母的替换为空。
sed -r ‘s#(1+)(:.?(.$)#\3\2\1#g’ 1.txt
sed -n ‘/user/p; /aming/p’ 1.txt
sed -n -e ‘/user/p’ -e ‘/aming/p’ 1.txt
sed -n -r ‘/usr|aming/p’ 1.txt
注释: sed '30,40s/^/##/ 1.txt

sed -r ‘s/([^:]+)(:.*: )([^:]+)/\3\2\1/’ /etc/passwd 匹配第一段除":“的任意字符 匹配第二段”:任意字符: “第三段 也是除开”:"的任意字符? \3\2\1 相当于把第一段和第三段对调
sed 使用外部变量,比如a=1,sed "/abc/ a / " 1. t x t 需 要 使 用 双 引 号 s e d ′ 1 , 5 s / . ∗ a/" 1.txt 需要使用双引号 sed '1,5s/^.* a/"1.txt使sed1,5s/./aaa&/’ 1.txt 和 sed ‘1,5s/^.*$/&aaa/’ 1.txt
sed ‘/ling/i hello world\nxiang’ 1.txt 匹配到ling,在前面增加hello world和xiang两行
sed ‘/ling/a hello world\nxiang’ 1.txt 匹配到ling,在后面增加hello world和xiang两行
sed ‘1,5 i hello world’ 1.txt
sed ‘1,5 a hello world’ 1.txt


  1. a-z0-9 ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值