问题
I have this fixed-width file with the widths being 34, 2, 3, 2, 1, 1, 3, 1, 2, 1, 2, 2 and 75 which I want to (a) convert to delimited (csv) format and then (b) subset according to V2="03" and V5="1". I have figured out the first step:
awk -v FIELDWIDTHS='34 2 3 2 1 1 3 1 2 1 2 2 75' -v OFS=',' '{ $1=$1 ""; print }' </filepath/Parse.txt > /filepath/Parse.csv
But I am stumped at step 2.
回答1:
Try with:
awk -v FIELDWIDTHS='...' -v OFS=',' '($2=="03") && ($5=="1"){ $1=$1 ""; print }'
来源:https://stackoverflow.com/questions/10102694/unix-linux-convert-fixed-width-file-to-csv-and-subset-on-two-columns