The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 10-10-2008
ShawnMilo ShawnMilo is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 252
Here's a fairly simple Python approach (tested and working).

Code:
$ cat nani123.py 
#!/usr/bin/env python

input = open("temp.txt", 'r')

for line in input:

    line = line.rstrip()
    line = line.split(',')
    num = line[0]
    data = line[1:]

    while data:
        print num + "," + ','.join(data[:3])
        data = data[3:]
Test:

Code:
$ cat temp.txt 
1,a,b,c,d,e,f,g,h
2,f,g,h,i,l


$ python nani123.py 
1,a,b,c
1,d,e,f
1,g,h
2,f,g,h
2,i,l