Results 1 to 4 of 4
I'm stuck with a script. Basically I have this file
01/28/09 04:03:02:383908 (00013011)
01/28/09 06:06:08:218152 (00002772)
01/28/09 06:08:36:849146 (00013551)
01/28/09 17:05:19:963716 (00012294)
01/28/09 17:11:14:630306 (00018351)
01/28/09 17:26:02:070358 (00010212)
01/28/09 19:44:44:877895 ...
- 01-29-2009 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 2
stuck with script looping
I'm stuck with a script. Basically I have this file
01/28/09 04:03:02:383908 (00013011)
01/28/09 06:06:08:218152 (00002772)
01/28/09 06:08:36:849146 (00013551)
01/28/09 17:05:19:963716 (00012294)
01/28/09 17:11:14:630306 (00018351)
01/28/09 17:26:02:070358 (00010212)
01/28/09 19:44:44:877895 (00018351)
01/28/09 21:21:07:593865 (00002670)
I want to loop though the numbers in the parenthisis and pass that to mysql which works. But I don't know how to keep the 1 to 1 relationship with the date and time
#driver_no is in () so we need to get it out of the ()
driver_no=`cat $2 | awk -F"(" '{print $2}' | awk -F")" '{print $1}'`
card_in_date=`cat $2 | awk '{print$1}'`
card_in_time=`cat $2 | awk '{print$2}'`
#Now we need to loop though the driver records and pull out the info
#appending commas between each so we can export it as a csv
for x in $driver_no
do
get_driver_info=$(mysql --user xxxx -pxxxx myDatabase -sN -e "Select Driver.driver_no, ',', Driver.name, ',', Driver.card_no,
',',Driver.carrier_no, ',', Carrier.name From Driver, Carrier Where Driver.carrier_no = Carrier.carr_no and Driver.driver_no = $x;")
now how do i append card_in_date and card_in_time to get_driver_info from the file above???
done
exit 0;Last edited by insomniac4104; 01-29-2009 at 02:30 AM. Reason: not clear enough question
- 01-29-2009 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Your use of awk is horribly inefficient. You can easily use read to do what you want:
And of course, you can use the variable references in your mysql statement as well.Code:IFS=' ()' while read a b c do echo _${a}_${b}_${c} done
- 01-29-2009 #3Just Joined!
- Join Date
- Jan 2009
- Posts
- 2
I desided to to it by line read reading the file line by line instead of awk the whole column in the file. I am a noob to scripting so if there is a better way to awk out the column I am all ears....
Thanks
while read line
do
#driver_no is in () so we need to get it out of the ()
#Now we need to loop though the driver records and pull out the info
#appending commas between each so we can export it as a csv
card_in_date=`echo $line | awk '{print $1}'`
card_in_time=`echo $line | awk '{print $2}'`
driver_no=`echo $line | awk -F"(" '{print $2}' | awk -F")" '{print $1}'`
get_driver_info=$(mysql --user xxx -pxxxxx $MyDB -sN -e "Select CONCAT_WS(',',Driver.driver_no,
Driver.name, Driver.card_no,Driver.carrier_no, Carrier.name) From Driver, Carrier Where Driver.carrier_no =
Carrier.carr_no and Driver.driver_no = $driver_no;")
echo $card_in_date","$card_in_time","$get_driver_info >> $2
done < $traceLogPath/tracelog.$1.tmp
- 01-30-2009 #4Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Was that a question?
Code:IFS=' ()' while read date time number do mysql ... "select * from whatever_table where date=${date} and number=${number}" done < input_file


Reply With Quote
