删除从另一个文件包含ID每一行 [英] Delete each line containing ID from another file

查看:152
本文介绍了删除从另一个文件包含ID每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个csv文件(list.csv),包含至极这样的事情:

I have a csv file (list.csv), wich contain something like that :

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

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

I have another file (delete.txt) :

"1"
"4"

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

I want to delete each line containing the ID from the delete.txt file. In my example, i want to display :

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

我怎样才能做到这一点?谢谢:)

How can I do that ? Thank you :)

推荐答案

在单次使用grep(你可以加一个回声$ ARG在结束时,如果要查看使用的查询):

Using grep in a single pass (you may add an echo "$arg" at the end if you want to see the query used) :

#!/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

这篇关于删除从另一个文件包含ID每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆