On 11-Aug-06 Laurie Brown wrote:
(Ted Harding) wrote:
Hi Folks,
I appeal to the ALUG Linux Consulate to rescue me, a citizen of Linux, from a foriegn and dangerous land!
I want to experimentally try running gawk on a Win98 system (the background is that a friend, currently working in Africa and stuck with Windows, could have the daunting task of restructuring the records in a CSV file solved in an awk 2-liner, instead of pulling hair out trying to do it in FoxPro).
[SNIP]
On Windows, the editor PFE32 has a good macro/learning facility which may assist you here. See:
http://www.lancs.ac.uk/staff/steveb/cpaap/pfe/pfefiles.htm
Cheers, Laurie.
Thanks for the pointer, Laurie! This looks a bit like 'vim' for Windows, perhaps plus a bit, according to the "Features":
http://www.lancs.ac.uk/staff/steveb/cpaap/pfe/features.htm
However, it doesn't look as though it would do the job in question (now thankfully solved diectly in FoxPro), which in 'awk' was a snip, namely (toy example):
data file (hh.dat):
1.1,1.2,1.3,1.4,1,hh1.1 2.1,2.2,2.3,2.4,2,hh2.1,hh2.2 3.1,3.2,3.3,3.4,6,hh3.1,hh3.2,hh3.3,hh3.4,hh3.5,hh3.6 4.1,4.2,4.3,4.4,4,hh4.1,hh4.2,hh4.3,hh4.4
where the 1st 4 (comma-sep) fields are data values, the 5th says how many instances of an "hh" there are, and the remainder are "hh" identifiers of hh's to which the data values apply. The problem is to split out the hh's into separate records, one for each hh.
Using 'awk':
cat hh.dat | awk 'BEGIN{FS=","} {nhh=$5; for(i=1;i<=nhh;i++){ hh=$(i+5); print($1 "," $2 "," $3 "," $4 "," hh) } }' 1.1,1.2,1.3,1.4,hh1.1 2.1,2.2,2.3,2.4,hh2.1 2.1,2.2,2.3,2.4,hh2.2 3.1,3.2,3.3,3.4,hh3.1 3.1,3.2,3.3,3.4,hh3.2 3.1,3.2,3.3,3.4,hh3.3 3.1,3.2,3.3,3.4,hh3.4 3.1,3.2,3.3,3.4,hh3.5 3.1,3.2,3.3,3.4,hh3.6 4.1,4.2,4.3,4.4,hh4.1 4.1,4.2,4.3,4.4,hh4.2 4.1,4.2,4.3,4.4,hh4.3 4.1,4.2,4.3,4.4,hh4.4
Could PFE32 do that? (Quote possibly 'vim' could do it, but I'd hate to write the macro!)
Cheers, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 11-Aug-06 Time: 15:49:56 ------------------------------ XFMail ------------------------------