我有一个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/