如何删除使用AWK具体线路基础的Sed /在另一个文件中的内容 [英] How can I delete specific lines using awk/sed based on the contents of another file
问题描述
我怎样才能删除基于行号包含在另一个文件中的文件中的特定行?我知道如何通过只提供他们在命令行中删除特定行,但我不知道如何删除基于被包含在另一个文件中的行号专用线。包含行号的文件是格式如下:
How can I delete a specific lines from a file based on line numbers that are contained in another file? I know how to delete specific lines by just providing them on the command line, but I do not know how to delete specific lines based on lines numbers that are contained in another file. The file containing the line numbers is in the following format:
15768
15775
15777
15782
15784
15789
15791
15798
15800
15807
15809
15815
15817
15824
15826
有2073行总说我需要删除。我试图寻找周围如何做到这一点,虽然我不能一个例子与此类似。
There are 2073 lines total that I need to remove. I've tried searching around for how to do this although I was not able to an example similar to this.
感谢您的帮助。
推荐答案
假设要删除的行号文件中的待删除
和数据在大数据文件
,然后,使用bash的进程替换:
Assuming the line numbers to be deleted are in a file to-be-deleted
and the data is in big-data-file
, then, using Bash process substitution:
sed -f <(sed 's/$/d/' to-be-deleted) big-data-file > smaller-data-file
内 SED的/ $ / D'
命令行号转换成 SED
删除操作。外 SED
命令读取删除命令,并应用操作的大数据文件。
The inner sed 's/$/d'
command converts the line numbers into sed
delete operations. The outer sed
commands reads the delete commands and applies the operations to the big data file.
这篇关于如何删除使用AWK具体线路基础的Sed /在另一个文件中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!