【问题标题】:How can I search the first word of the last line of a file and then find it in another file to delete the next line with that pattern in unix?如何搜索文件最后一行的第一个单词,然后在另一个文件中找到它以在 unix 中删除具有该模式的下一行?
【发布时间】:2018-04-27 08:59:11
【问题描述】:

这是第一个文件说 FILE1.txt 的详细信息:

aardvar 555-5553 1200/300 B
alponet 555-3412 2400/1200/300 A
barflyx 555-7685 1200/300 A
bitesup 555-1675 2400/1200/300 A
camelot 555-0542 300 C

然后在另一个文件中搜索模式“camelot”,比如 FILE2.txt 并删除具有该模式的下一行。

【问题讨论】:

标签: linux bash shell unix


【解决方案1】:
word=$(tail -n1 FILE1.txt | awk '{print $1;}')
grep -v $word FILE2.txt > FILE2.txt.modified

但是,这仅适用于单词在 FILE2.txt 中仅出现一次的情况。

【讨论】:

  • 嗨罗宾感谢您的回答。我可以删除“Word”中存储的内容旁边的行吗?
  • 对不起,我不明白
  • 这里 Camelot 是 FILE1 中的最后一行,所以我想将它保留在 FILE2 中并删除它之后的行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多