简体   繁体   English

两个列表之间的grep

[英]grep between two list

I have a file ( list.txt ) containing a list of objects and another file informations.txt that contain a longer list of objects in the first column (containing also the objects of the file 1) and in the others columns some variables.我有一个包含对象列表的文件 ( list.txt ) 和另一个文件informations.txt ,其中包含第一列中更长的对象列表(也包含文件 1 的对象),其他列中包含一些变量。 I need to extract from the file informations.txt only the line that regarding the objects present in file list.txt .我只需要从文件informations.txt提取关于文件list.txt存在的对象的行。 Example:例子:

list.txt:
1ert3_001_______
4rt41_004_______

informations.txt: All the column are separated by "tab"
1ert3_001_______ GVT YTR 456
76ftr_008_______ TRF cFR 3k9
r45e9_001_______ YTG %&Y TF2
4rt41_004_______ %&/ ldu DR4

result.txt:
1ert3_001_______ GVT YTR 456
4rt41_004_______ %&/ ldu DR4

I tried to use the comand grep but I didn't obtain the desidered results.我尝试使用命令 grep 但我没有获得所需的结果。

如果您使用的是 GNU grep,请将 -f --file 与 -F --fixed-strings 结合使用以从文件中搜索固定(非正则表达式)模式:

grep --fixed-strings --file list.txt informations.txt
while read p; do
  grep -i "$p" informations.txt
done <list.txt

Try this.尝试这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM