Script request

Jing Su jingsu-26n5VD7DAF2Tm46uYYfjYg at public.gmane.org
Sun Apr 25 20:43:36 UTC 2004


> I have over 2000 records of theare following pattern
>
> PMPART,PMPAR1,PMPAR2,PMPAR3,PMPAR4,PMPAR5
> 0000183209,000021032004,0000Q21032004,,,
> 0000493059,000049030504,,,,
> 0000670609,000067060004,0000Q67060006,,,
> 0000676609,0000Q67060006,,,,
> 0000833189,1510833189,,,,
> 0000833209,000071032004,(00007103209),,,
> 0000Q11030604,0000Q11030606,,,,
> 0000Q11030806,9005-3008,,,,
> 0000Q11040804,0000Q11040806,,,,
> 0000Q11041506,9005-4015,,,,
> 0000Q11050006,0000Q61050006,,,,
> 0000Q11051006,9005-4010,,,,
> 104222008A,104022008A,102121001A,102321001A,1560015150,1020021330
>
>
> I would need a script to create the following, two column output with the
> first column followed by the second. If more than 2 fields then create
> another record with the first field followed by the third field, if there
> are 4 fields then create another record with first field followed by the
> fourth field and so on ... there will be a max of 6 fields.
>
>
> Ouput :
>
> 0000183209,000021032004
> 0000183209,0000Q21032004
> 0000493059,000049030504
> 0000670609,000067060004
> 0000670609,0000Q67060006
>

Here's an ugly one off the top of my head that might work.  Double check
it first before you use it.  Corrections welcome.

cat data.txt | awk -F ',' '{for (i=2; i <= NF; i++) {if (length($(i)) > 0) {printf("%s,%s\n", $1, $(i))}}}'
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list