Script request

Chris F.A. Johnson c.f.a.johnson-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org
Sun Apr 25 20:50:37 UTC 2004


On Sun, 25 Apr 2004, Tony Pinto wrote:

> 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

while read line
do
   set -- ${line//,/ }
   f1=$1
   shift
   for f
   do
     printf "%s,%s\n" "$f1" "$f"
   done
done < FILE

-- 
	Chris F.A. Johnson                      http://cfaj.freeshell.org
	=================================================================
                Everything in moderation -- including moderation
--
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