- 论坛徽章:
- 2
|
回复 6# iamkey9 - head format.txt data
- ==> format.txt <==
- #keywords IFS fieldNo
- #===================
- clock " " 4
- month " " 4
- day " " 9
- location "-" 4
- ==> data <==
- The clock shows "12:00:00"
- The month is "Jan" and the day is "31"
- The-location-is-Beijing-(China)
- awk 'NR>2&&NR==FNR{a[gensub(/ /,"","g",$1)]=$2;b[gensub(/ /,"","g",$1)]=gensub(/ /,"","g",$3)}
- NR>FNR{if(/location/){t=a["location"];split($0,c,t);print c[2],": "c[b[c[2]]]};
- if(/month/){t=a["month"];l=split($0,c,t);print c[2],": "c[b[c[2]]] RS "day: "c[b["day"]]};
- if(/clock/){t=a["clock"];split($0,c,t);print c[2],": "c[b[c[2]]]};delete c}
- ' FS='"' format.txt data
- clock : "12:00:00"
- month : "Jan"
- day: "31"
- location : Beijing
复制代码 |
|