Home » Infrastructure » Unix » process one file at a time
process one file at a time [message #309204] Wed, 26 March 2008 15:27 Go to next message
shree_z
Messages: 75
Registered: February 2008
Member
I have a Unix program which looks for particular files by their names say A*.txt,in a directory and then process the files.

here is the part of the code.

ls -lrt A*.txt | awk '{print $9}' | while read fname
do....
...
done


I have registered this as a host concurrent program in Apps.
As of now, the program looks for all A*.txt and processes all of them.

But I have a change request, that needs this program to be scheduled to run every one hour or so and process only one file at a time.

The problem here is, if there are more than one file with the same naming convention, which file would the program choose to process?

If the name of the file includes date and time, is there a way to modify the batch program so that it chooses the latest file to process? If yes, could anyone please tell me how this can be done..

Thanks in advance
Re: process one file at a time [message #309206 is a reply to message #309204] Wed, 26 March 2008 15:31 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
pipe results thru
tail -1
Re: process one file at a time [message #309207 is a reply to message #309206] Wed, 26 March 2008 15:34 Go to previous messageGo to next message
shree_z
Messages: 75
Registered: February 2008
Member
Thanks for your immediate response.

could you please give an example of the code with the output

[Updated on: Wed, 26 March 2008 15:45]

Report message to a moderator

Re: process one file at a time [message #309220 is a reply to message #309204] Wed, 26 March 2008 17:57 Go to previous messageGo to next message
ebrian
Messages: 2794
Registered: April 2006
Senior Member
You can avoid using AWK with simply:
ls -1tr A*.txt | tail -1

[Updated on: Wed, 26 March 2008 19:17]

Report message to a moderator

Re: process one file at a time [message #309487 is a reply to message #309220] Thu, 27 March 2008 12:47 Go to previous message
shree_z
Messages: 75
Registered: February 2008
Member
Thanks a lot for the reply!!

its working!!

Thanks a ton
Previous Topic: Error in send_mail
Next Topic: Tail Command
Goto Forum:
  


Current Time: Tue Dec 03 14:28:08 CST 2024