I have the following CSV file:
Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa
1000,"1 0 0 1",1002,1002,1003,1004,1005,"1 0 0 6",1007,1008,1009,1010,1011,1012,1013
100,101,102,102,103,104,105,"1 0 6 2",107,108,109,110,111,112,113
10001,10011,10021,10021,10031,10041,10051,10061,10071,10081,10091,10101,10111,10121,10131
.
.
.
.
My target is to set the CSV parameters ( all states in CSV ) with their values in my bash script
for example
#!/bin/bash
Alabama=1000
.
.
.
Iowa=1013
so in my bash script I can read each parameter
example
echo $Alabama
1000
First I just tried to write the following (wrong) code, in order to set the parameters with their values:
#!/bin/bash
counter=1
for CSV_COLUMN in Alabama Alaska Arizona Arkansas California Colorado Connecticut Delaware Florida Georgia Hawaii Idaho Illinois Indiana Iowa
do
export $CSV_COLUMN=` echo $CSV_LINE | cut -d',' -f$counter `
counter=$counter+1
done
The test should be (from the bash script)
echo $Alabama
1000
How should I change my code in order to implement my idea?
$ALABAMA
is not very useful since you will never see that name written, it would only be available to the program internally. I think what you're after will be solved by using arrays but please explain what kind of processing your script will be doing. – terdon♦ Jul 15 '14 at 16:55