LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   unix shell script loop concept (https://www.linuxquestions.org/questions/linux-software-2/unix-shell-script-loop-concept-759091/)

badrinath_tcs 10-01-2009 06:24 PM

unix shell script loop concept
 
Hi Friends ,

I have a file called LOG_FILE.lst and having saple data as below
177,PARE0120_30092009_182957.log
511,PARE0120_30092009_012001.log
171,PARE0120_30092009_181551.log
507,PARE0120_30092009_020915.log

i want to capture read the whole file and want to capture the fisrt ,separate filed in a variable called job_id .

I user the below code but its not working ..

for i in $(cat LOG_FILE.lst)
do
job_id = `echo $i |awk -F"," '{print $1}'`
echo "$job_id"
done

when I am printing the job_id as echo "$job_id"
it prints nothing .


Could you suggest what is wrong in the code .

sploot 10-01-2009 06:28 PM

As far as I can tell, you aren't assigning the variable to the return of `echo....`
Change it to job_id=`echo...` with no spaces.

chrism01 10-01-2009 07:01 PM

Just to reinforce sploot, it's a quirk of bash (all shells I believe) that when assigning values to variables, there must be no spaces around the assignment operator ie '=', so

x=5 # ok
x = 5 # nada

badrinath_tcs 10-01-2009 07:11 PM

I found the error .Thanks chrism01 ..

I have spent 1 hour for this small mistake i.e a space was present in the assignment statement.


All times are GMT -5. The time now is 09:18 PM.