2016-04-13 79 views
2

我有一個csv文件(list.csv)包含ID的每一行,至極含有類似的東西:刪除從另一個文件

"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" 

我該怎麼做?謝謝:)

回答

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 
+0

太好了,謝謝:) – Kamiz

2

你可以試試這個:

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

它從delete.txt中讀取所有行,傳遞給sed以進行刪除。

+0

如果你用'-I',你不需要'-L 1'。 – 123

+1

你是對的@ 123。更新。 – SLePort

相關問題