sed 命令删除指定行

mcck_hyj
  • 200

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

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

回复
阅读 1.2k
2 个回答
✓ 已被采纳

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

sed -i 'Nd' filename N为行数

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏