Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k 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 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...