I have been trying to write a simple snip of bash shell code to import from 1 to 100 records into a BASH array.
I have a CSV file that is structured like:
record1,item1,item2,item3,item4,etc.,etc. .... (<= 100 items)
record2,item1,item2,item3,item4,etc.,etc. .... (<= 100 items)
record3,item1,item2,item3,item4,etc.,etc. .... (<= 100 items)
record4,item1,item2,item3,item4,etc.,etc. .... (<= 100 items)
record5 ......
record6 ......
...... and so on
I am trying to get this data into corresponding arrays as such:
$record1[item1-n]
$record2[item1-n]
$record3[item1-n]
$record4[item1-n]
Here is what i have so far:
++++++++++++++++++++++++++++++
#!/bin/bash
testfile="./test-dev/test-global-data-import.csv"
var1=`cat $testfile`
IFS=',' record1=( ${var1} )
echo ""
echo "Here is the data without the comma separators."
echo ""
echo ${record1
[*]:0}
echo ""
echo "Here is the data with comma separators."
echo ""
echo "${record1
[*]:0}"
echo ""
#EOF
++++++++++++++++++++++++++++++
Here are the problems I am having:
-
I am trying to have each record (line in the CSV file) become its own array, such as $record1
[*] -
There will be lots of strange formatting within the CSV file (i.e. IP addresses, street addresses w/ commas and periods) and right now each record has items 1-35 and it could possibly grow to <=100 fields.
-
I am a newbie .... I have edited BASH scripts in the past ... but that no way make me proficient .... so can someone please help.
P.S. I am pouring over several resources on a daily basis (Beginners & Advanced BASH guides on tldp.org and I have a BASH book that I have my nose buried in constantly. I still need some expert assistance though. :wall:
Any help is greatly appreciated.