我希望从file2.txt打印整个字符串,但它只打印77但不是File2.txt中的整个匹配字符串任何帮助表示赞赏。 谢谢,
脚本
awk '
BEGIN {
OFS="\t"
out = "File3.txt"}
NR==FNR && NF {a[substr($0,1,8)]=$0; next}
function print_77_99() {
if (key in a)
print "77", a[key] > out
}
$1 == "01" {
if (FNR > 1) print_77_99()
key = $4 $3 $2
lines = ""
}
{ print > out
lines = lines $0 "\n" } END {print_77_99()}
' File2.txt File1.txt
FILE1.TXT
01 89 68 5000
02 83 11
04 83 9 02
03 83 00
06 83 00
07 83 11 RT0429
01 44 73 8800
02 44 73
04 44 73 02
03 44 73
06 44 73
07 44 11 RT 0789
FILE2.TXT
50006889RT0429 NARD /3010 /E /C A87545457 / // ///11 ///
51002387 NARD /3000 /E /S N054896334IV / // ///11 ///
File3.txt(当前输出)
01 89 68 5000
02 83 11
04 83 9 02
03 83 00
06 83 00
07 83 11 RT0429
77
01 44 73 8800
02 44 73
04 44 73 02
03 44 73
06 44 73
07 44 11 RT 0789
所需输出
01 89 68 5000
02 83 11
04 83 9 02
03 83 00
06 83 00
07 83 11 RT0429
77 50006889RT0429 NARD /3010 /E /C A87545457 / // ///11 ///
01 44 73 8800
02 44 73
04 44 73 02
03 44 73
06 44 73
07 44 11 RT 0789
答案 0 :(得分:0)
我认为错误在函数中:
function print_77_99() {
if (key in a)
print "77", line[key] > out
}
您在a
数组中保存File2.txt内容,但稍后尝试从line
数组中读取它。请改用a
,例如:
function print_77_99() {
if (key in a)
print "77", a[key] > out
}