The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 05:23 AM
Reading the particular line from the file eamani_sun Shell Programming and Scripting 3 05-16-2008 05:55 PM
reading text file line by line MizzGail Shell Programming and Scripting 6 04-14-2008 07:58 AM
Reading line by line from a file tej.buch Shell Programming and Scripting 2 01-23-2006 02:50 AM
Reading line by line from file. akpopa UNIX for Dummies Questions & Answers 4 08-30-2001 11:20 PM

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 07-20-2007
ProFiction ProFiction is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
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
  #2 (permalink)  
Old 07-26-2007
tangjava tangjava is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 1
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
  #3 (permalink)  
Old 07-26-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,423
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.
  #4 (permalink)  
Old 07-26-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
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
  #5 (permalink)  
Old 07-26-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
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
  #6 (permalink)  
Old 07-26-2007
LAKSHMI NARAYAN LAKSHMI NARAYAN is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 38
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
  #7 (permalink)  
Old 07-26-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
Could you please post the contents of the input_line file and not_proceeded_line file
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 07:32 AM.


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