Hello all! After searching through numerous helpful posts on these forums I am still having an issue with a task I am trying to accomplish.
I am trying to take data from an input file, store the contents as variables, and use the variables in the script.
The input file (input.txt) is composed of 3 values: name, number, state. For example:
Quote:
John Doe, 555-123-4567, Texas
Jane Doe, 555-321-7654, Oklahoma
Jim Doe, 555-000-1111, California
Jeane Doe, 555-111-0000, New York
The main script requires the data to be in the same order but without the commas, i.e:
After researching these forums I have come up with the following script that takes the data and puts it in an array:
Quote:
awk -F "," '{
array[$0] = array[$0] " " $1 " " $2 " " $3;
}
END {
for (i in array)
print array[i];
}' input.txt
Verifying with the print command, the array is properly formated how the main script needs it. Now the issue I am having is using the contents of the array in the variables for my main script. The script creates a single file using variables I want filled from the array.
Here is an abridged version of the main script using manually entered data in the variables:
Quote:
#!/bin/bash
cust=("John Doe");
tele=("555-123-1456");
state=("Texas");
echo "Please enter batch name: "
read batchname
echo "Creating "$batchname".txt..."
counter=${#cust[@]}
index=0
while [ "$index" -lt "$counter" ]
do
echo -e "\nCustomer Name:\t\t"${cust[$index]}"\n\tPhone:\t\t\t"${tele[$index]}"\n\tState:\t\t\t"${state[$index]}"\n" >> $batchname".cfg"
let "index = $index +1"
done
exit 0
I am trying to get the data from the array (taken from input.txt) to be used in the 3 variables in the main script (cust, tele, state), but with no luck.
The output file will be formatted as such:
Quote:
batchname.txt
Name: John Doe
Phone: 555-123-1234
State: Texas
Name: Jane Doe
Phone: 555-321-4321
State: Oklahoma
etc, etc...
Please let me know if you have any questions or need clarification on the issue I am having.
Thanks in advance!