LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-01-2009, 06:24 PM   #1
badrinath_tcs
LQ Newbie
 
Registered: Sep 2009
Posts: 6

Rep: Reputation: 0
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 .
 
Old 10-01-2009, 06:28 PM   #2
sploot
Member
 
Registered: Sep 2009
Location: Phoenix, AZ
Distribution: Gentoo, Debian, Ubuntu
Posts: 121

Rep: Reputation: 27
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.
 
Old 10-01-2009, 07:01 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,873

Rep: Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600
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
 
Old 10-01-2009, 07:11 PM   #4
badrinath_tcs
LQ Newbie
 
Registered: Sep 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script question $variable in loop icecubeflower Linux - Newbie 2 03-31-2009 09:09 AM
shell script , while loop ykc Programming 5 03-30-2009 07:50 AM
Shell Script skipping a loop dnvikram Programming 2 01-23-2009 02:29 PM
Loop in Shell Script delamatrix Programming 4 07-24-2008 05:20 PM
shell script - while loop with multiple conditions ronsha Programming 13 12-10-2005 04:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration