如何保持以数字列表开头的行(Linux)?
我有一个如下所示的文件:
0 123 word
1 324 word
2 234 word
3 53 word
4 666 word
5 23 word
6 4 word
...
我一直试图仅保留以某些数字开头的行。我的文件中的数字如下所示:
2
4
5
...
因此最终文件应如下所示:
2 234 word
4 666 word
5 23 word
...
我想我可以使用 grep (grep "2" input > output) 获取以特定字符开头的行,但是通过以下方式进行操作一个不可行,我不知道如何对文件中的数字列表执行此操作。有人可以帮我吗?
I have a file that looks like this:
0 123 word
1 324 word
2 234 word
3 53 word
4 666 word
5 23 word
6 4 word
...
I have been trying to keep only the lines starting with some numbers. I have the numbers in a file that looks like this:
2
4
5
...
So the final file should look like this:
2 234 word
4 666 word
5 23 word
...
I think I can get lines starting with a specific character using grep (grep "2" input > output), but doing it one by one is not viable and I do not know how to do it for a list of numbers in a file. Could someone help me with that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 GNU awk:
其中
file1
包含要保留的数字,每行一个,file2
是要过滤的文件。With GNU awk:
where
file1
contains the numbers to keep, one per line, andfile2
is the file to filter.