User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 391,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,643 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 825 | Replies: 4 | Solved
Reply
Join Date: Mar 2008
Posts: 20
Reputation: guest7 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
guest7 guest7 is offline Offline
Newbie Poster

Help with while loop and sed

  #1  
May 25th, 2008
Hi,

Following is my code :

i=3
j=3
while [ $i -le $count1 ]
do
i=`expr $i + 3`
head -n 60 file1.imp >> s27.txt
while [ $j -le 60 ]
do
head -n 3 file2.imp >> s27.imp
./prog1 s27.txt > result.txt
if grep OUT result.txt
then
head -n 3 file1.imp >> final.imp
num=`expr $num + 1`
else
k=`expr $j -3`
sed "$j,$k d" file1.imp > f1.imp
mv f1.imp file1.imp
fi
sed '1,3d' file2.imp > f2.imp
mv f2.imp file2.imp
j=`expr $j +3`
done

I am checking 3 lines from file2 at a time.

I am getting the following error in while loop and sed command. I am trying to delete 3 lines from the file1.

Error: expr: syntax error
sed: 1: "3, d": expected context address
expr: syntax error
line 21: [: -le: unary operator expected

Can I use a while loop inside a while loop. Is there something wrong in my syntax for sed and while.

Please help.

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 256
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: Help with while loop and sed

  #2  
May 25th, 2008
Hey There,

I'll check this out. What are you trying to delete and what are the spec's for deletion? For the code you posted, you're missing a closing "done" for the outside while loop. It's perfectly okay to do a while loop within a while loop, I'm just thinking it might be easier to do this in a different way.

Thanks,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Join Date: Oct 2007
Posts: 256
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: Help with while loop and sed

  #3  
May 25th, 2008
Sorry,

Looks like the count1 variable isn't set either and it's used in a arithmetic test right at the beginning. If possible, could you cut and paste the entire code and post it in [code] tags. It seems that the entire program isn't here.

Thanks

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Join Date: Mar 2008
Posts: 20
Reputation: guest7 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
guest7 guest7 is offline Offline
Newbie Poster

Re: Help with while loop and sed

  #4  
May 26th, 2008
I got the mistake. There was a space missing in the expression j = j+ 3.

Thanks guys...
Reply With Quote  
Join Date: Oct 2007
Posts: 256
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: Help with while loop and sed

  #5  
May 26th, 2008
Good catch Those spaces'll getcha every time, especially since expr is different than "let" arithmetic and I often get the two confused

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 11:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC