End of file with while loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting End of file with while loop
# 1  
Old 10-06-2011
End of file with while loop

(sh shell) I have a function I am using that does a date calculation so I can subtract dates.
Code:
get_JD () {
bc << MSG
scale=0
date calculation  ……….......
MSG
}

Then I have this little script that runs after it.
Code:
read XXX < TESTFILE
pastdate=`get_JD $XXX`
currdate=`get_JD &YYY`
diff=`expr $currdate - $pastdate`
echo $diff

The only problem is that it only reads the first line in my file named TESTFILE. Is there a way to write a while loop so that it can keep working until it reaches the end of this file? Or is there a better way to do this?

Last edited by jim mcnamara; 10-06-2011 at 11:49 AM.. Reason: use code tags please
# 2  
Old 10-06-2011
use a while loop to read a file
Code:
while read XXX 
do
  pastdate=`get_JD $XXX`
  currdate=`get_JD &YYY`
  diff=`expr $currdate - $pastdate`
  echo $diff
done  < TESTFILE

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 10-06-2011
Thanks Jim! Works great.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help on Adding one counter loop at the end of each line in a file

Hello All, I have file a.txt I want to add a counter loop at the end of each line in a file ill explain: i have a site h**p://test.test=Elite#1 i want to add a a counter to the number at the end of the file, that it will be like this urlLink//test.test=Elite#1 urlLink//test.test=Elite#2... (3 Replies)
Discussion started by: nexsus
3 Replies

2. Shell Programming and Scripting

Nested While loop doesn't end

Hi, Below is my script in which i am using nested while loop to read two files and move the files to a remote server. My issue is that the 2nd while loop doesn't stop executing and it keeps on executing. Can someone please let me know where i have gone wrong. myFile=$ESER_TEST_FILES ... (2 Replies)
Discussion started by: funonnet
2 Replies

3. Shell Programming and Scripting

for loop two commands at the end

cat vfiler_volumes.list | while read var1 var2 ; do ssh -n "$var1" df -h "$var2" >> test this part works, however i would like to add an echo $var1 >> test before each ssh iteration. any pointers ? thanx (1 Reply)
Discussion started by: riegersteve
1 Replies

4. Shell Programming and Scripting

while loop to add text to the end of a file

Hi all, I've got 2 files. File 1 has a list say a b c d e f File 2 got start= What I want is to create File 3 which look like this start=a,b,c,d,e,f So is it possible to loop throught File1 to echo it into File3 in one line? (3 Replies)
Discussion started by: stinkefisch
3 Replies

5. Shell Programming and Scripting

Why doesn't this loop end?

Simple script, takes an cmd line argument and counts down to 1. NUMBER=$1 # One argument must be provided, otherwise don't execute if then echo "Error. Enter one argument " exit 0 elif then echo " " fi # Integer value must be greater than zero while do echo... (6 Replies)
Discussion started by: Breakology
6 Replies

6. Shell Programming and Scripting

for loop not working - syntax error at line 6: `end of file' unexpected

I have a file called test.dat which contains a b I have written a shell script called test.sh for i in `cat test.dat` do echo $i done When i run this script using sh test.sh I get this message - test.sh: syntax error at line 6: `end of file' unexpected What is the... (3 Replies)
Discussion started by: debojyoty
3 Replies

7. Shell Programming and Scripting

Limits of FOR loop to go to end of File

Hi ALL:), I have a file for e.g. ajdflkj|dkj|djfj|go|123|4||||||||||||||89|101||||||||||||||| The length of file is not fixed. So wat the limits should be given in for loop to access till end of file???? Thanks in advance..... (2 Replies)
Discussion started by: rohiiit.sharma
2 Replies

8. Shell Programming and Scripting

End of loop condition required???

Hi i have a variable with lots of tokens seperated with spaces. e.g VAR="ABC DEF GHSD GHQS TUTSD JHDTQ QDHQ CDQKDGQ WQUTQD DQUTQD DQJGDQ QDTQD WDQUTQDU QDUGQD QDJGQD DQUTDUQ QDUIDTQ" i want to separate all of the above tokens and call a script with each of the token e.g sh script.sh <TOKEN>... (4 Replies)
Discussion started by: skyineyes
4 Replies

9. Shell Programming and Scripting

Why does rexec cause while loop to end prematurely?

I have the following korn shell script which reads the contents of an ascii file and performs an rexec command based on the line that was just read from the ascii file. The ascii file contains 6 lines, thus, the while loop should execute 6 times. The problem is that the rexec command within the... (2 Replies)
Discussion started by: sadove
2 Replies

10. Shell Programming and Scripting

TCSH.need help.take input during a while/end loop

I am writting a script in csh and I am blanking out on how I code in the ability to process user input in the middle of a while/end loop. while(1) args.. end it is a simple script, and I want to add hotkey functions, like q to quit, z to zero counters, etc.. Google has not been very... (1 Reply)
Discussion started by: seg
1 Replies
Login or Register to Ask a Question