Extract values from specific row, column using bash
问题 I have a sample log file with fields and values in this format value1 value2 50 100 value3 value4 10 150 value5 200 I need to extract fields and values to something of this format value1=50 value2=100 value3=10 value4=150 value5=200 回答1: Try this awk: gawk '{split($0,n_arr," "); getline; n=split($0,v_arr," "); getline; for (i=1;i<=n;i++){print n_arr[i] "=" v_arr[i]}}' 回答2: awk '/value/ { if ((getline values) > 0) { split(values, array) for (i = 1; i <= NF; i++) print $i "=" array[i] } }'