Question : Modify a text file with a shell script using multiple variables.

OK, let's say I have a text file with the following data:

Customer Address
$customer
$street-no
$town-city, $state, $zip

And I want to grab info from a database and replace each of the markers in the file and create a new file for each customer's info. OK, I know how to do this with one variable, what I don't know is how to do this with multiple variables. I have a while loop that uses awk, however it only replaces the first customer information then quits. I hope it's just a small syntax error on my part or something. Thanks for you help. Here is the code that I have so far:
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
awk '{print $1, $2, $3, $4, $5, $6}' database-file | while read customer street-no town-city state zip filename
do
    echo "Customer Address" >> $filename
    echo "$customer" >> $filename
    echo "street-no" >> $filename
    echo "$town-city, $state, $zip" >> $filename
done
Open in New Window Select All

Answer : Modify a text file with a shell script using multiple variables.

OK,
your script should work fine, given your 'database-file' has the correct structure:
Each line of this file must consist of six blank-separated  (or whatever your IFS value is) words and be terminated by a 'newline' character.
If in doubt, you should post the first few lines of this file, so we can have a look at it.

 wmp

Random Solutions  
 
programming4us programming4us