The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read some lines from file!!! andy2000 Shell Programming and Scripting 7 03-28-2007 05:55 AM
how to read lines one by one from a file bihani4u UNIX for Dummies Questions & Answers 5 09-28-2006 08:55 PM
How to read lines from a flat file bihani4u Shell Programming and Scripting 2 09-28-2006 02:54 PM
Read the lines from the file in batch amitraorane Shell Programming and Scripting 2 01-26-2006 01:51 PM
How to read specific lines in a bulk file using C file Programming rajan_ka1 High Level Programming 10 11-10-2005 03:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2006
sagolo sagolo is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 7
Read lines from file

i have a problem on my bourne shell script. I want to read line by line and then stop when the line does not have letters or is an empty string. But i encounter an error at "while [ read line -a $stop -eq 0 ]". The error nessage is "test.sh: test: unknown operator line". Can anyone help me on this thanks

Quote:
#!/bin/sh

counter=1
stop=0

exec < /export/home/admin/test.sh

while [ read line -a $stop -eq 0 ]

### If reached 5th or greater row, means we have reached the rows
### as input
if [ $counter -gt 4 -a $stop -eq 0 ]
then
executed=`echo $line | awk '{ print $1 }'`


### If reached 4th or greater row and it is blank, means we have reached
### the end of the daily reocrd
elif [ $counter -gt 4 -a "'$line'" = "" ]
then
stop=1
echo "End of line"
fi

### Increment row counter by 1
counter=`expr $counter + 1`


done
done
  #2 (permalink)  
Old 11-27-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960
something like this,


Code:
#! /bin/zsh

while read line
do
if [ ${#line} -eq 0 ]
then
break
fi
echo $line
done < out

exit 0

  #3 (permalink)  
Old 11-27-2006
jam_prasanna jam_prasanna is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 21
Hi,

I have done the necessary changes for the code, pls check now, hope it should work now.

also u have used $count > 4, but u have initialized $count to 1
instead of using > u can use <= it will work, if u use > then script will hang, pls change it accordingly n then run the script

#!/bin/sh

counter=1
stop=0

read line < /export/home/admin/test.sh

while [ read line -a $stop -eq 0 ]

do

### If reached 5th or greater row, means we have reached the rows
### as input
if [ $counter -gt 4 -a $stop -eq 0 ]
then
executed=`echo $line | awk '{ print $1 }'`


### If reached 4th or greater row and it is blank, means we have reached
### the end of the daily reocrd
elif [ $counter -gt 4 -a "'$line'" = "" ]
then
stop=1
echo "End of line"
fi

### Increment row counter by 1
counter=`expr $counter + 1`


done
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0