I am having a blonde moment.
This is my data from myfile.csv
1429829254,e,SE,StckXchg,HDCU3000623,d,scan,253,47968,94,1420824420,JSSE-213,199,BS,KIT,*OUT*
1429897704,e,SE,StckXchg,HDCU3000623,d,scan,253,68496104,103,1420923818,SP-TMX6BP-101-112Z,*OUT*
1429897718,e,SE,StckXchg,HDCU3000623,d,scan,253,68510090,104,1420923832,02132,*OUT*
1429897767,e,SE,StckXchg,HDCU3000623,d,scan,253,68559085,105,1420923878,02132,*OUT*
1429912759,e,SE,StckXchg,HDCU3000623,d,scan,255,47966,107,1420924040,JSF-1,4"MEG0004,*OUT*
1429912766,e,SE,StckXchg,HDCU3000623,d,scan,255,54955,108,1420924047,02134,*OUT*
1429982863,e,SE,StckXchg,HDCU3000623,d,scan,256,47965,120,1420987942,JSDL-JA120901S,*OUT*
1429982870,e,SE,StckXchg,HDCU3000623,d,scan,256,54953,121,1420987961,02132,*OUT*
1429982877,e,SE,StckXchg,HDCU3000623,d,scan,256,61954,109,1420971277,02134,*OUT*
I currently put this data into an array and extract each of the elements individually.
But our input data has changed and now there the elements with a line can vary- and can vary by a lot. I was curious to know how I can extract data from the above sample, from the 12th element up until the last element.
With my code this is what I do:
cat $out_file_name | while read line
do
awk_var=`echo "$line" | awk -F"," '{print $1, $5, $10, $12, $13, $14}'` #Get the appropriate arguments
awk_var_array=($awk_var)
timestamp=${awk_var_array[0]}
container==${awk_var_array[1]}
scan_id=${awk_var_array[2]}
part_no=${awk_var_array[3]}
direction=${awk_var_array[4]}
#further processing and send the above to a mysql table
done
but now this obviously doesn't work. So I need to find a way of storing all the element from the 12th element till the last element (in/out).
would it be done with a for loop? Something like this perhaps?
for element_count in $(seq 13 $({#awk_var_array[@]}-1))
do
var_name=my_var_''$element_count
$var_name=${awk_var_array[element_count]
done
while IFS=, read timestamp x x x container x x x x scan_id x part_no direction rest ; do ...some_processing... ; done < file.csv
. – Janis Apr 27 '15 at 5:34echo
, pipes,awk
, arrays, etc.; rather just a loop over the csv file entries and aread
to "unique identifiers" for your processing. The code would get quite simple and performant. - But to be sure that would require that you post the surrounding loop code (how you read the csv file) and explain the further processing of your variables (it doesn't seem you need them stored in arrays). - Note: the 'x' in my code are ignored fields. – Janis Apr 27 '15 at 5:45while read line
from a csv file. I process the data - concatenate some identifiers then shoot it off over to a mysql table... – 3kstc Apr 27 '15 at 5:50