Reading line of text

Hi,
Maybe a biggy but I want to make it clear what i'm trying to achieve......

I'm a big stuck and need a bit of a pointer. I'm not sure how to explain this. :confused:

My input file follows the format below. When I read the file each time I get a ~FILE? I want to assign it to var1 then each num/value that is comma seperated will be assigned to var2 and used to execute a diff comamnd/script.

Example: script ~FILE1 1
script ~FILE1 2

File format. (lines beginning with comma , are continuation of previous line and are new line seperated after 7 entries, numbers will never follow a sequence like in this example)
~FILE1,1,2,3,4,5,6,7
,8,9
~FILE2,1a,2a,3a
~FILE3,1b,2b,3b,4b,5b,6b,7b
,8b,9b,10b,11b

Once a get to the next ~FILE? that becomes var1 and subsequent , comma speerated fields become var2 and are used on the same script.

Example: script ~FILE2 1a

How can I read the line and seperate each in the way that I want? I have played around with read and shift and a few other no hopers to achive nothing. I end up with var1 and var2 being the same string I get no strings assigned to either var.

Any help will be great.....

Cheers and beers to the winner.... :smiley:

Only joking on the beer...unless winner collects....

You don't say which shell you are using. This is bash but might work for ksh...

while read line
do
    IFS=','
    eval set $line
    if [[ $1 == ~* ]]
    then
        param1=$1
        shift
    fi
    while [[ $# -gt 0 ]]
    do
        echo script $param1 $1
        shift
    done
done < filein

The result is...

script ~FILE1 1
script ~FILE1 2
script ~FILE1 3
script ~FILE1 4
script ~FILE1 5
script ~FILE1 6
script ~FILE1 7
script ~FILE1 8
script ~FILE1 9
script ~FILE2 1a
script ~FILE2 2a
script ~FILE2 3a
script ~FILE3 1b
script ~FILE3 2b
: