Variables while reading a file with multiple rows in a list - python or shell
Question: I am looking to do this in python or a basic shell script.

I have a file with multiple entries that I would like to manipulate its data
and store them in variables.

The file has rows with multiple columns. The first column is a person's name
(i.e., Joe, Mary, etc). The second (after the comma) is an ID. I would like to
store each ID into a variable and then construct some links as shown below.
The problem is that one name can have only one ID or multiple, as you can see
below:

    
    
    Joe, 21142 21143 21909 24125
    Mary, 22650 23127
    John, 24325
    Mike, 24683 24684 26973
    

How can I store each value in the "second column" into a variable so I can
then construct links like this:

    
    
    http://example/Joe/21142
    http://example/Joe/21143
    http://example/Joe/21909 
    http://example/Joe/24125
    http://example/Mary/22650 
    http://example/Mary/23127
    

Thank you in advance!

  * Omar


Answer: can be done with `GNU awk`

    
    
    awk -F'[, ]+' '{for (i=2; i<=NF; ++i) print "http://example/"$1"/"$i }' input.txt
    http://example/Joe/21142
    http://example/Joe/21143
    http://example/Joe/21909
    http://example/Joe/24125
    http://example/Mary/22650
    http://example/Mary/23127
    http://example/John/24325
    http://example/Mike/24683
    http://example/Mike/24684
    http://example/Mike/26973
    

Or in Python

    
    
    s = '''Joe, 21142 21143 21909 24125
    Mary, 22650 23127
    John, 24325
    Mike, 24683 24684 26973
    '''
    from StringIO import StringIO
    from contextlib import closing
    with closing(StringIO(s)) as f:
        for line in f: 
                x, y = line.split(',')
                x = x.strip()
                y = y.strip().split()
                leader = 'http://example/{}'.format(x)
                print '\n'.join('{}/{}'.format(leader, z) for z in y)
    

