search last modified file and process it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search last modified file and process it
# 1  
Old 09-12-2010
search last modified file and process it

Hello,

trying to build a shell script that

- searches in defined location for similar files (eg. containing pattern in file name)
- Identifies last modified
- stores name in variable for processing

Thanks a lot

Last edited by alice07; 09-12-2010 at 08:08 AM..
# 2  
Old 09-12-2010
What have you attempted so far and where do you get stuck?

Regards
# 3  
Old 09-12-2010
I'm not good at all.

I'm trying something like:

ls -l -t | grep "pattern"
...
I know how to manipulate file with some awk instructions.
What I'm missing is the way to extract most recent filename and storing that to a variable.
Thanks
# 4  
Old 09-12-2010
You are not far off the mark..
Code:
myfilename=$(ls -rt | grep 'pattern' | tail -1)
# do stuff with $myfilename  here ....

# 5  
Old 09-12-2010
Great !!
That's it !!!
SmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need to search for keywords within files modified at a certain time

I have a huge list of files in an Unix directory (around 10000 files). I need to be able to search for a certain keyword only within files that are modified between certain date and time, say for e.g 2012-08-20 12:30 to 2012-08-20 12:40 Can someone let me know what would be the fastest way... (10 Replies)
Discussion started by: virtual123
10 Replies

2. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

3. Shell Programming and Scripting

Start/Stop process when a file is modified.

I have a file which is modified via a web application & this may happen during any time of the day/week. This file is being used a config/list file for another shell script which runs 24hrs with a sleep of 200 secs. I have writted a small script to kill the shell script when this config file is... (4 Replies)
Discussion started by: Lancel0t
4 Replies

4. Shell Programming and Scripting

How to get a filename modified by attaching modified timestamp

Hi, I want to modify a filename in AIX by attaching the last modified timestamp. I want the timestamp completely in numerical format (eg:200905081210. yr-2009, mnth - 05, date -08, hr - 12, mins - 10). For example if the filename is a.log and it was modified on April 6th 2008 at 21.00. I... (16 Replies)
Discussion started by: Ruks
16 Replies

5. Shell Programming and Scripting

How can i search a file which has been created or modified in last five minutes

Hi Can some one please help me How can i search a file which has been created or modified in last five minutes I have used the command find . -mmin -5 and it does not work i get an error -mmin is bad option Please help Much regards Tarun (2 Replies)
Discussion started by: tarundeepdhawan
2 Replies

6. Shell Programming and Scripting

search and add same line modified in iptables

I have in iptables file the following: -A RUN -p tcp -m tcp -s ipaddress1 --dport xxx --syn -j ACCEPT -A RUN -p tcp -m tcp -s ipaddress2 --dport xxx --syn -j ACCEPT And I want to add for each ipaddress1 and ipaddress2 another IP address Like this: -A RUN -p tcp -m tcp -s ipaddress1... (2 Replies)
Discussion started by: Mansor
2 Replies

7. Shell Programming and Scripting

search by modified date

Hello, How can i search for all the files in a particular directory which are not updated from past 5 days. Thanks, Sateesh (4 Replies)
Discussion started by: kotasateesh
4 Replies

8. UNIX for Dummies Questions & Answers

how to retrieve original contents of a modified file (modified using vi)

Made changes to a file using vi editor and saved those changes now realised that the changes are not required How can I get the previous version of the file.i.e the one which was there on which I had made changes (3 Replies)
Discussion started by: novice100
3 Replies

9. UNIX for Dummies Questions & Answers

who modified my file!!

Hi EVERYONE!!... Just a simple (yet critical from my perspective) doubt... I would like to know who had edited my file.. when I use ls -l command, I see my ID.. but when I edit using some other ID, I had expected that ID to be shown.. but still ls -l shows my ID only.. So, is there any... (4 Replies)
Discussion started by: mohanprabu
4 Replies

10. Programming

File last modified

I cannot read the last moment the file was modified - it returns "Most recent access" instead: code: </td> <th><?FILE *fatr=fopen(iindname.c_str(), "r"); if(fatr){ struct stat statbuf; fstat(fileno(fatr), &statbuf); fclose(fatr); ?> ... (4 Replies)
Discussion started by: szzz
4 Replies
Login or Register to Ask a Question