我有一个文件也需要清除一些 URL。URL 位于一个文件中,比如 fileA 和 CSV fileB(这些是大小为 6-10 GB 的大文件)。我尝试了以下 grep 命令,但它不适用于较新的 fileB。
grep -vwF -f patterns.txt fileB.csv > result.csv
文件 A 的结构是一个 URL 列表,如下所示:
URLs (header, single column)
bwin.hu
paradisepoker.li
和文件B:
type|||URL|||Date|||Domain
1|||https://www.google.com|||1524024000|||google.com
2|||www.bwin.hu|||1524024324|||bwin.hu
fileB 的分隔符是 |||
我对包括 awk 在内的所有解决方案持开放态度。谢谢。
编辑:预期输出是 CSV 文件,保留所有与 fileA 中的域模式不匹配的行
type|||URL|||Date|||Domain
1|||https://www.google.com|||1524024000|||google.com
你能不能试试以下。
awk 'FNR==NR{a[$0];next} !($NF in a)' Input_filea FS="\\|\\|\\|" Input_fileb
或者
awk 'FNR==NR{a[$0];next} !($NF in a)' filea FS='\|\|\|' fileb
输出如下。
type|||URL|||Date|||Domain
1|||https://www.google.com|||1524024000|||google.com
说明:现在为上面的代码添加说明。
awk ' ##Starting awk program here.
FNR==NR{ ##Checking condition FNR==NR which will be TRUE when first Input_file named filea is being read.
a[$0] ##Creating an array named a whose index is $0(current line).
next ##next keyword will skip all further statements.
} ##Closing block for condition FNR==NR here.
!($NF in a) ##Checking condition if last field of current line is NOT present in array a for Input_fileb only.
##if condition is TRUE then no action is mentioned so by default print of current line will happen.
' filea FS="\\|\\|\\|" fileb ##Mentioning Input_file names and for fileb mentioning FS should be ||| escaped it here so that awk will consider it as a literal character.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句