这是我的工作测试文件
Name Column1 Column2 Column3 Column4
Dir01 val1 val2 val3 val4
Dir01 val5 val6 val7 val8
Dir01 val9 val10 val11 val12
我想要的输出是这样的
for loop over row elements
For Dir01
Column1 = val1
Column2 = val2
Column3 = val3
Column4 = val4
For Dir02
Column1 = val5
Column2 = val6
Column3 = val7
Column4 = val8
For Dir03
Column1 = val9
Column2 = val10
Column3 = val11
Column4 = val12
done
答案1
awk '
NR==1{split($0,h); next}
{print "For " $1; for(i=2;i<=NF;i++) printf "\t%s = %s\n", h[i], $i}
' file
For Dir01
Column1 = val1
Column2 = val2
Column3 = val3
Column4 = val4
For Dir01
Column1 = val5
Column2 = val6
Column3 = val7
Column4 = val8
For Dir01
Column1 = val9
Column2 = val10
Column3 = val11
Column4 = val12