이것은 내 작업 테스트 파일입니다.
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