I have a file that ends up just having numbers in each line, like the following.
Code:
1234575
12475
275473636
24757392
I want to set each number in its own array element with in a bash script. I have been searching and trying to get this to work with no such luck. Any advice or tips would be most appreciated. I have posted the script below.
Thank you,
Kyle
Code:
#!/bin/bash
declare -a ORDERIDARRAY
COUNTER=0
i=0
########
# Set ORDERIDs from email.txt in an array.
#
cat email.txt |cut -d " " -f 1|grep ^[0-9] > temp-array.txt
########
# Get each line of temp-array.txt and set it as an array element.
#
########
# This is one way that I found on the net but cant seem to get it to work.
old_IFS=$IFS
IFS=$'\n'
ORDERIDARRAY=($(cat temp-array.txt))
IFS=$old_IFS
########
# Another way was this yet again did not work.
#exec 3<./temp-array.txt || exit 1
#let COUNTER=0
#while read currentline <&3; do
# ORDERIDARRAY=("${ORDERIDARRAY[@]}" "$currentline")
#done
#exec 3<&-
########
# echo each element in ORDERIDARRAY
#
for ((i=0; i<$ORDERIDARRAY; i++))
do
echo ${ORDERIDARRAY[${i}]}
done
rm temp-array.txt