删除用awk从基于最后字符的文本文件线,是在另一个文件或sed的 [英] deleting lines from text files based on the last character which are in another file using awk or sed
本文介绍了删除用awk从基于最后字符的文本文件线,是在另一个文件或sed的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件,xx.txt,是这样的。
1PPYA
2PPYB
1GBND
1CVHA
该文件的第一行是1PPYA。我想
- 阅读的最后一个字符1PPYA。在这个例子中,它的A /
- 从YY目录查找1PPY.txt(第4个字符)。
- 删除行以CSH,它包含A字。
由于下面的1PPY.txt中的YY目录:
CSH 1 A 1 27.704 6.347
CSH 2 A 1 28.832 5.553
CSH 3 A 1 28.324 4.589
CSH 4 B 1 27.506 3.695
CSH 5℃1 29.411 4.842
CSH 6 A 1 28.378 4.899
所需的输出是:
CSH 4 B 1 27.506 3.695
CSH 5℃1 29.411 4.842
解决方案
这可能会为你工作:
SED的| ^ * \\ \\ $(* \\)(\\)| sed的-i.bak。/ ^ * CSH * \\ 2 / DYY / \\ 1.TXT |' xx.txt | SH
N.B。我添加了一个文件备份。如果不需要修改 -i.bak
到 -i
I have a file, xx.txt, like this.
1PPYA
2PPYB
1GBND
1CVHA
The first line of this file is "1PPYA". I would like to
- Read the last character of "1PPYA." In this example, it's "A/"
- Find "1PPY.txt" (the first four characters) from the "yy" directory.
- Delete the lines start with "csh" which contain the "A" character.
Given the following "1PPY.txt" in the "yy" directory:
csh 1 A 1 27.704 6.347
csh 2 A 1 28.832 5.553
csh 3 A 1 28.324 4.589
csh 4 B 1 27.506 3.695
csh 5 C 1 29.411 4.842
csh 6 A 1 28.378 4.899
The required output would be:
csh 4 B 1 27.506 3.695
csh 5 C 1 29.411 4.842
解决方案
This might work for you:
sed 's|^ *\(.*\)\(.\)$|sed -i.bak "/^ *csh.*\2/d" yy/\1.txt|' xx.txt | sh
N.B. I added a file backup. If this is not needed amend the -i.bak
to -i
这篇关于删除用awk从基于最后字符的文本文件线,是在另一个文件或sed的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文