Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

sed 命令删除指定行

record 文件里有以下数据

1607583364561;/app/rm/a.x;./a.x;1210145604
1607583364561;/app/rm/b.x;./b.x;1210145604
1607583364561;/app/rm/c.x;./c.x;1210145604
1607583364561;/app/rm/d.x;./d.x;1210145604
1607587139072;/app/rm/a.b;a.b;20201210155859
1607587139072;/app/rm/a.c;a.c;20201210155859
1607587139072;/app/rm/a.d;a.d;20201210155859
1607587139072;/app/rm/a.e;a.e;20201210155859

我需要删除其中一行

sed "/1607587139072;/app/rm/a.b;a.b;20201210155859/d" /record

结果返回
1607583364561;/app/rm/a.x;./a.x;1210145604
pp/rm/a.x;./a.x;1210145604/p
1607583364561;/app/rm/b.x;./b.x;1210145604
pp/rm/a.x;./a.x;1210145604/p
1607583364561;/app/rm/c.x;./c.x;1210145604
pp/rm/a.x;./a.x;1210145604/p
1607583364561;/app/rm/d.x;./d.x;1210145604
pp/rm/a.x;./a.x;1210145604/p
1607587139072;/app/rm/a.b;a.b;20201210155859
1607587139072;/app/rm/a.c;a.c;20201210155859
1607587139072;/app/rm/a.d;a.d;20201210155859
1607587139072;/app/rm/a.e;a.e;20201210155859

我想可能是正则表达式中带有/,添加转译后

sed '/1607587139072;/app/rm/a.b;a.b;20201210155859/p' /tmp/recycle/.record
1607583364561;/app/rm/a.x;./a.x;1210145604
1607583364561;/app/rm/b.x;./b.x;1210145604
1607583364561;/app/rm/c.x;./c.x;1210145604
1607583364561;/app/rm/d.x;./d.x;1210145604
1607587139072;/app/rm/a.b;a.b;20201210155859
1607587139072;/app/rm/a.b;a.b;20201210155859
1607587139072;/app/rm/a.c;a.c;20201210155859
1607587139072;/app/rm/a.d;a.d;20201210155859
1607587139072;/app/rm/a.e;a.e;20201210155859

全部都被输出了,请问我想删除指定的任意一行应该怎么做?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

我试了转译后可以删掉啊?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...