Ha! Ha! Ha!
Be patient,
If it works manually on the command line then
it will work in a script.
Prior to posting my initial solution, I created a small csv file
and looped through the output displaying lines and also
cutting things up to display individual values.
So I KNOW the looping script works.
NOTE: I did not use quotes inside my csv file.
The only variable left in question was Tsql which works
manually.
Why not give all the information you can so my script
will look very much like the end result.
Additional note:
Be careful of your syntax, the loop you posted will not work
Code:
while read line
do
Route="$(echo $line | cut -d, -f1)"
Stop="$(echo $line | cut -d, -f2)"
Change="$(echo $line | cut -d, -f3)"
Passangers="$(echo $line | cut -d, -f4)"
Time="$(echo $line | cut -d, -f5)"
echo $Route
echo $Stop
done < /home/carver/rider1.txt
Here is my sample csv file located in the same directory
as my shell script, I'll name it rider1.txt
Code:
one1,one2,one3,one4
two1,two2,two3,two4
three1,three2,three3,three4
four1,four2,four3,four4
Here is the same loop you posted, but slight syntax
adjustments were needed, I named it csv_script.sh
Code:
#!/bin/env bash
while read line
do
Route="$(echo $line | cut -d, -f1)"
Stop="$(echo $line | cut -d, -f2)"
Change="$(echo $line | cut -d, -f3)"
Passangers="$(echo $line | cut -d, -f4)"
Time="$(echo $line | cut -d, -f5)"
echo $Route
echo $Stop
done < ./rider1.txt
I make it executable by:
chmod 777 ./csv_script.sh
Here is my shell output:
Code:
[debtboy@nixbox ~]$ chmod 777 ./csv_script.sh
[debtboy@nixbox ~]$ ./csv_script.sh
one1
one2
two1
two2
three1
three2
four1
four2
[debtboy@nixbox ~]$
Maybe your csv file structure is an issue and as
for the Tsql, there are many ways to resolve that.
I'll try to get another post in the next half hour.
I'll also be on tonight, don't get discouraged
it will work and you'll learn some scripting!!
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum