找出与指定集合有共同成员的行

针对需要从Data.txt中提取与List.txt共有的行的问题,通过将Data.txt的某字段转换为集合并与List.txt做交集运算,可以得到理想结果。文中提到尝试Shell脚本未成功,建议使用SPL语言,利用其集合运算符"^"进行交集操作,从而简洁高效地解决这个问题。
摘要由CSDN通过智能技术生成

【问题】

I needed to extract all hits from one list (list.txt) which can be found in one of the columns of another (here in Data.txt) into a third (output.txt).

Data.txt (tab delimited)

some\_data more\_data other\_data here yet\_more_data etc
A B 2 Gee;Whiz;Hello 13 12
A B 2 Gee;Whizz;Hi 56 32
E 4 Btm;Lol 16 2
T 3 Whizz 13 3

List.txt

Gee
Whiz
Lol

Ideally output.txt looks like

some\_data more\_data other\_data here yet\_more_data etc
A B 2 Gee;Whiz;Hello 13 12
A B 2 Gee;Whizz;Hi 56 32
E 4 Btm;Lol 16 2

So I tried a shell script

for ids in List.txt
do
grep $ids Data.txt >> output.txt
done

except I typed out everything (cut and paste actually) in List.txt in said script.

Unfortunately it gave me an output.txt including the last line, I assume as ‘Whizz’ contains ‘Whiz’.

I also tried cat Data.txt |

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值