我有两个文件:
1.txt:
j_e_s_s_i_c_a_a_n_n [email protected] /cdn-cgi/l/email-protection 61b8a203438ea1c56c1489ec7bea7a0e
9871951 [email protected] /cdn-cgi/l/email-protection 671cb9239bf797a082f723a07a9c713f
holliebrian [email protected] /cdn-cgi/l/email-protection a2e531ea7df55290c35d74082f38f020
9075407 [email protected] /cdn-cgi/l/email-protection d20f83ee6933aa1ea047fe5cbd9c1fd5
9837056 [email protected] /cdn-cgi/l/email-protection e4d11b1c62cfbb7bfb49e4644e70d476
2.txt:
a2e531ea7df55290c35d74082f38f020:182:@*/
671cb9239bf797a082f723a07a9c713f:1199
e4d11b1c62cfbb7bfb49e4644e70d476:abcd123
d20f83ee6933aa1ea047fe5cbd9c1fd5:33;1:11
我想要这两个文件作为输出:
一个是 left.txt,其中 1.txt 的行的第三列 (FS = ' ') 与 2.txt 的第二列 (FS = ':') 不匹配
左.txt:
j_e_s_s_i_c_a_a_n_n [email protected] /cdn-cgi/l/email-protection 61b8a203438ea1c56c1489ec7bea7a0e
另一个文件是 result.txt,其中 1.txt 中的所有行都包含 2.txt 中的匹配项。但在输出文件中,匹配的第三列应替换为匹配的行第二列(FS = ':')
结果.txt:
9871951 [email protected] /cdn-cgi/l/email-protection 1199
holliebrian [email protected] /cdn-cgi/l/email-protection 182:@*/
9075407 [email protected] /cdn-cgi/l/email-protection 33;1:11
9837056 [email protected] /cdn-cgi/l/email-protection abcd123
我编写了一个脚本来实现相同的任务:
awk -F : 'FNR==NR {s=$0;sub(/[^:]*:/, "", s); p[$1]=s; next} !($NF in p) {print > "left.txt"; next} {$NF=p[$NF]} 1' 2.txt FS=' ' OFS=' ' <(tr -d '\r' < 1.txt) > result.txt
我得到了预期的输出,但在更大的文件 1.txt (~ 3GB) 和 2.txt (~ 1 GB) 上。该脚本因以下错误而崩溃:
awk:命令。行:1:(FILENAME = 2.txt FNR = 21085923)致命:
/home/corinna/src/gawk/gawk-4.2.0/gawk-4.2.0-1.x86_64/src/gawk-4.2.0/node.c:1021:more_blocks:
freep: 无法分配 9600 字节内存 (Cannot allocate memory)
请帮助我使脚本运行更大的文件。任何帮助将不胜感激。使用 awk 不是必须的。唯一的座右铭是在更短的时间内完成正确的工作并且不崩溃。