Constructing a string by reading the contents of 2 files

Hi all - I am trying to write a script to generate a string that gets sent to an IP phone using wget. This is to upload a phone book of up to 100 entries so the string needs to be constructed in one 'hit'. I am a relative newbie to shell scripts but willing to try anything! I have 2 files:

File 1 - this is simply a list of decimal values that refer to parameters the remote device needs to refer to. There are 100 records in this file. The format is:

17253
17927
18291
18485
18676
...

File 2 - this is a CSV list of users and extension numbers. There could be anything from 1 to 100 records in this file. The format is:

Bob Smith,0501234567
Steve Gray,0507654321
Craig Hancox,0506515272
...

What I need to do is this define a string which will ultimately get sent to the phone using wget. This is construced in the following way:

1) Read the first record in File 2 (Name/Number)

2) If the record exists (i.e., not EOF), read the first record of file 1

3) Construct a string which is basically File 1: Data plus 'some text' plus File 2: Field 1 plus 'some text' plus File 2: Field 2 plus 'some text'

(note that File 2:Field 1 may contain spaces and it would really be useful of I could replace these with %20).

4) Repeat the above sequence and concatenate the results into the primary string

5) Exit the string construction phase once EOF has been reached of File 2

I can do the wget side fine - this is working... its just the string construction thing I am having real issues with. Problems I have had have been:

  • Getting the script to exit after EOF of File 2
  • Using awk to do the string manipulation on what it reads out of File 2

Any help or pointers would be much appreciated and i would be eternally grateful!

Best regards,

Sean

one way:

exec 4<22
while read record
do
 IFS="," read user extn <&4
 if [ "$user" ] && [ "$extn" ]; then
 echo "$record some text $user some text $extn some text"
 fi
done < 11
4<&-

11 is the file1, 22 is the file2

Hi,

Try this,

paste -d, 11 22 | sed 's/.*,$/d' | sed 's/,/ SOME TEXT /g'

11 is the file1, 22 is the file2

Thanks guys - this is exactly what I wanted - obviously I have some way to go! Anyway thanks a million...

Cheers

Sean