October 2001
Intermediate to advanced
1040 pages
22h 50m
English
Some data (e.g., that read in from tape or from a spreadsheet) may not have obvious field separators but may instead have fixed-width columns. To preprocess this type of data, the substr function is useful.
In the following example, the fields are of a fixed width, but are not separated by a field separator. The substr function is used to create fields.
% cat fixed 031291ax5633(408)987–0124 021589bg2435(415)866–1345 122490de1237(916)933–1234 010187ax3458(408)264–2546 092491bd9923(415)134–8900 112990bg4567(803)234–1456 070489qr3455(415)899–1426 % nawk '{printf substr($0,1,6)" ";printf substr($0,7,6)" ";\ print substr($0,13,length)}' fixed 031291 ax5633 (408)987–0124 021589 bg2435 (415)866–1345 ... |