gpt4 book ai didi

bash - 从另一个文件中删除包含 ID 的每一行

转载 作者:行者123 更新时间:2023-11-29 09:46:42 24 4
gpt4 key购买 nike

我有一个 csv 文件 (list.csv),其中包含类似的内容:

"1","10","1","2"
"2","22","20","2"
"3","33","5","2"
"4","36","225","2"
"5","36","225","2"

我有另一个文件(delete.txt):

"1"
"4"

我想从 delete.txt 文件中删除包含 ID 的每一行。在我的示例中,我想显示:

"2","22","20","2"
"3","33","5","2"
"5","36","225","2"

我该怎么做?

最佳答案

单次使用 grep(如果您想查看使用的查询,可以在末尾添加 echo "$arg"):

#!/bin/bash
arg=""
for i in `cat delete.txt`; do
if [ -n "$arg" ]; then
arg="$arg\|^$i"
else
arg="^$i";
fi
done;
grep -v "$arg" input.txt

关于bash - 从另一个文件中删除包含 ID 的每一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36590840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com