I have a file named /etc/values, with the following 3 lines:
Code:
Gonzales, Juan;California;June
Johnson, Paul;Wyoming;April
Smith, John;Wisconsin;February
I'm trying to figure out how to use the read command and need a little advice. I'd like run a script that prints out:
Code:
Name: Gonzales, Juan
State: California
Month: June
Name: Johnson, Paul
State: Wyoming
Month: April
Name: Smith, John
State: Wisconsin
Month: February
Here is my script so far:
Code:
#!/bin/sh
## Set IFS variable to semicolon as delimiter
IFS=;
for i in `cat /etc/values`; do
echo $i | read -a field
echo -e "Name:\t${field[0]}"
echo -e "State:\t${field[1]}"
echo -e "Month:\t${field[2]}"
done
But it's not working.
The output I am getting is:
:
I have read "man bash" and have tried many variations, but still not working right. If you have any tips, or see what I am doing wrong, feel free to point it out.
NOTE: The actual file I'll be using will have hundreds of records, delimited by a semicolon. Within the fields, there will be spaces and commas.