While loop reading a record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop reading a record
# 1  
Old 03-25-2009
Bug While loop reading a record

Hi,

I am trying to create a while loop that will do the following:

INFILE= list of new records that need to be added after last previous record
while read record
do
find the last record processed
create list of new records output to a file
echo "$record">> $NEWFILE
done

Please advice. Thank You in advance
# 2  
Old 03-25-2009
what do you mean by last previous record??
# 3  
Old 03-25-2009
the INFILE will be a file of new records that need to be added to a file sorry.
# 4  
Old 03-25-2009
I know I'm missing something but you want to add records in one file to another existing file - and add them at the end, right?
Code:
cat newrecordsfile >> oldrecordsfile

oldrecordsfile now has added all of the records in newrecordsfile
# 5  
Old 03-25-2009
The thought process with this is you have the INFILE being updated every ten minutes lets say. So in the while loop you would read the record of the INFILE. Find the last record in the INFILE that was processed in another file called fileB. Create a new list called OUTFILE that captures the new files that need to be updated in fileB that was not processed after the last update of INFILE.

Hope this explains more.
# 6  
Old 03-25-2009
I might be missing something, but...
Code:
tail -f newrecordsfile >> oldrecordsfile

# 7  
Old 03-25-2009
that is only going to give me the last line. I need the last file processed in FileB to be in the starting point of where i left off in FileA. For example if i have FileA getting updated every ten minutes. FileA could start off with 1234 in the file that i send to FileB. So now FileB is 1234. But after 10 min FileA is now 123456. How do i send 456 to the end of FileB?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Record count checking for multiple files through for-loop

Hi Friends, I wrote one shell script to check the record count in two files and that will send us the notification activity if found zero record count. What i did is I created for loop and checking the count for both of the files but what is happening is for first file has data then it's... (13 Replies)
Discussion started by: victory
13 Replies

2. Shell Programming and Scripting

ksh while read loop breaks after one record - AIX

#!/bin/ksh for SRV in imawasp01 \ imawasp02 \ imawasp03 \ imawasp04 \ imawasp05 \ imawasp06 \ imawasp07 \ imawasp08 \ imawasp09 do print "${SRV}" while read PASSLINE do SRVNAME=`echo ${PASSLINE} | awk -F\: '{print $1}'` LASTLOGIN=`ssh ${SRV} lsuser ${SRVNAME} | tr '... (2 Replies)
Discussion started by: port43
2 Replies

3. Shell Programming and Scripting

Update file record inside read loop

Hi, I am reading file records inside a while loop, and want to update the record when certain condition is met. How can I update a file while being read? I want to avoid using temporary files, copy, rename, ... while IFS=',' read -r f1 f2 do function(f1,f2) if then <add... (1 Reply)
Discussion started by: ysrini
1 Replies

4. Shell Programming and Scripting

Unable to read the first space of a record in while loop

I have a loop like while read i do echo "$i" . . . done < tms.txt The tms.txt contians data like 2008-02-03 00:00:00 <space>00:00:00 . . . 2010-02-03 10:54:32 (2 Replies)
Discussion started by: machomaddy
2 Replies

5. Shell Programming and Scripting

Parsing issue while reading excel having 3000 record

Hi Need urgent help (2 Replies)
Discussion started by: premp26
2 Replies

6. Shell Programming and Scripting

Reading input record from inside nawk

Hi friends, I have small query with reg to awk search pattern.. below is my sample file and code which i tried.. $ cat file.txt xxx,yyyyy,messageID,sha xxxx,errorcode,messageID,name in the above sample file - let assume I know the errorcode(2nd record) using which I want to... (2 Replies)
Discussion started by: Shahul
2 Replies

7. UNIX for Dummies Questions & Answers

Reading only first record from the multipe directories

Hi All, I have a requirement, I had a parent directory Land under that we have sub directories Yesterday, Today and Tommorrow And we have a file test.txt under the above directories Yesterday, Today and Tommorrow The data in the file test.txt under Yesterday folder is ... (5 Replies)
Discussion started by: somu_june
5 Replies

8. Shell Programming and Scripting

Reading a file (one record) in a SHL script

I am trying to read a file in a shl script (only one record) and stored in a variable file_number I got the following read -u $BANNER_HOME/xxxxxxx/misc/EFTSQL.dat file_number file_number2 = $file_number + 1 echo $file_number2 > $BANNER_HOME/xxxxxx/misc/EFTSQL.dat EOF It is not working... (2 Replies)
Discussion started by: rechever
2 Replies

9. UNIX for Advanced & Expert Users

"while read ..." loop exiting after reading only one record

Greeting, The following script completes after reading only one record from the input file that contains many records. I commented out the "ssh" and get what I expect, an echo of all the records in the input.txt file. Is ssh killing the file handle? On the box "uname -a" gives "SunOS... (2 Replies)
Discussion started by: twk
2 Replies

10. Shell Programming and Scripting

problem in reading a record from the file

Hi Guys, I need to check whether the last column is RP, If so, then i have to second column and pass it to a select statement as sonid and fetch the value to a variable and run it. This has to be done till the last column is RW. value Fatherid sonid topid ... (8 Replies)
Discussion started by: mac4rfree
8 Replies
Login or Register to Ask a Question