The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reading ps command's output line by line s. murat Shell Programming and Scripting 5 05-22-2008 01:23 AM
Reading the particular line from the file eamani_sun Shell Programming and Scripting 3 05-16-2008 01:55 PM
reading text file line by line MizzGail Shell Programming and Scripting 6 04-14-2008 03:58 AM
Reading line by line from a file tej.buch Shell Programming and Scripting 2 01-22-2006 10:50 PM
Reading line by line from file. akpopa UNIX for Dummies Questions & Answers 4 08-30-2001 07:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-20-2007
Registered User
 

Join Date: Jul 2007
Posts: 5
Stumble this Post!
Line by line file reading... and more!

Hello,

I've got a lot of this file replication script written, but I'm having trouble finishing it off. What I need to do at the moment is run through a file one line at a time, execute the line, then check the time.

The process cannot run past 7am.

I've got a while loop set up to handle the time, I just need the innards of the loop to go through the file one line at a time.

The file looks like this:
cp /path/to/file /path/to/new/file
...... etc over and over again.

Also, if it reaches 7am and the file is not completed, its remaining contents must be saved for the next night.

Any help at all would be greatly appreciated.

Code:
hour="`date '+%H'`"
while [ $hour -ne "07" ]
do
    // read/execute next line of the file
    hour="`date '+%H'`"
done
//once it is 7am, save the remainder of the file until the next night.
The reading/executing just a single line of the file and also saving the rest of it is what I'm having troubles with
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-26-2007
Registered User
 

Join Date: Jul 2007
Posts: 1
Stumble this Post!
line by line reading

if you do the following it should work:-

cat "$OUTFILE" | while read LINE; do
.
.
done

where $OUTFILE is the name of your file
Reply With Quote
  #3 (permalink)  
Old 07-26-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Stumble this Post!
You can do something like that :
Code:
> not_proceeded_lines
hour="`date '+%H'`"
while read input_line
   if [ $hour -ne "07" ]
   then
      echo "Proceed line ..."
      hour="`date '+%H'`"
   else
      echo "$input_line" >> not_proceeded_lines
   fi
done < input_file

Jean-Pierre.
Reply With Quote
  #4 (permalink)  
Old 07-26-2007
Registered User
 

Join Date: Aug 2005
Location: Bangalore
Posts: 196
Stumble this Post!
alternatively you can use this:

Quote:
hour="`date '+%H'`"
for input_line in `cat input_file`
do
if [ $hour -ne "07" ]
then
echo "Proceed line ..."
hour="`date '+%H'`"
else
echo "$input_line" >> not_proceeded_lines
fi
done
Reply With Quote
  #5 (permalink)  
Old 07-26-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Stumble this Post!
Quote:
Originally Posted by ProFiction View Post
Hello,
I've got a lot of this file replication script written, but I'm having trouble finishing it off. What I need to do at the moment is run through a file one line at a time, execute the line, then check the time.
The process cannot run past 7am.
...
This is a duplicate post.

I already replied with a solution to the previous post:
http://www.unix.com/shell-programmin...#post302128241
Reply With Quote
  #6 (permalink)  
Old 07-26-2007
Registered User
 

Join Date: Mar 2007
Posts: 37
Stumble this Post!
hey i tried this script

the output is giving like this

PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
PROCEED THE LINE
---------------------------------------------------------------------
the script which i tried and u have given is


hour="`date '+%H'`"
for filename in `cat input_line`
do
if [ $hour -ne "07" ]
then
echo "PROCEED THE LINE"
hour="`date '+%H'`"
else
echo "$input_line" >> not_proceeded_line
fi
done


---------------------------------------------------------------------

can u explain this , what was it doing
Reply With Quote
  #7 (permalink)  
Old 07-26-2007
Registered User
 

Join Date: Aug 2005
Location: Bangalore
Posts: 196
Stumble this Post!
Could you please post the contents of the input_line file and not_proceeded_line file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0