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

时间:2016-04-13 06:59:03

标签: bash awk sed grep

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

<form id="myform" method="POST" ng-submit="submitForm()">
  <input type="text" name="city" id="city" ng-model="city">{{ city }}
  <button type="submit">Click Here</button>
</form>

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

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

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

"1"
"4"

我该怎么做?谢谢:))

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:2)

你可以试试这个:

< delete.txt xargs -I % sed -i '/%/d' list.csv

它读取delete.txt中的所有行,并传递给sed进行删除。