Take only lastest file matching the pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Take only lastest file matching the pattern
# 1  
Old 07-25-2014
Take only lastest file matching the pattern

Hi All ,

I have some fille names in a file which are sorted according to date. for example

Code:
 
 file1_123.log  23 Jul 0Kb
 file2_123.log  22 Jul 2Kb
 file3_123.log  20 Jul 0Kb
 file1_456.log  24 Jul 2Kb
 file2_678.log  22 Jul 0Kb
 file2_678.log  21 Jul 2Kb

here 123 is a particular Order No. I want to pick only the latest files for a particular order no.

My final output should be
Code:
 
 file1_123.log  23 Jul 0
file1_456.log  24 Jul 2
 file2_678.log  22 Jul 0


I have tried sorted the file into a file but I am having no idea on how to proceed from here. any code sample will be very much appreciated.

OS - AIX
# 2  
Old 07-25-2014
Code:
awk -F'[_|.]' '!a[$2]++' file

# 3  
Old 07-28-2014
Thanks all
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies

2. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 Replies

3. Shell Programming and Scripting

Get matching string pattern from a file

Hi, file -> temp.txt cat temp.txt /home/pradeep/123/a_asp.html /home/pradeep/123/a_asp1.html /home/pradeep/435/a_asp2.html /home/pradeep/arun/abc/a_dfr.html /home/pradeep/arun/123/a_kir.html /home/pradeep/123/arun/a_dir.html .... .... .. i need to get a_*.html(bolded strings... (4 Replies)
Discussion started by: pradebban
4 Replies

4. Shell Programming and Scripting

Help with matching pattern inside a file

I have a huge file that has roughly 30304 lines. I need to extract specific info from that file. For example, Box 1 > *aaaaaaaajjjj* > hbbvjvj > jdnnfddllll > *dgdfhfekwjh* Box 2 > *aaaaaaa'aj'jjj* > dse hkjuejef bfdw > dyeee > dsewq > *dgdfhfekwjh* >feweiuei Box 3 > *aaaa"aaaaj"jjj* >... (25 Replies)
Discussion started by: Ernst
25 Replies

5. UNIX for Dummies Questions & Answers

PERL pattern matching in a file

Hi Gurus, I have a file like below.. I have to match each with predefined pattern. If matches then have to write the entire record to a separate file. If not make the value as NULL and write the entire record into another file. | is the delimiter ravi123|2344|M R123Vi|2345|F... (8 Replies)
Discussion started by: pvksandeep
8 Replies

6. Shell Programming and Scripting

To find files by matching a pattern in file name

Hi all, I have to check whether certain files exist using a if statement. I have to check this by matching a pattern of filename: e.g. if ] This statement should be "true" if any files like test.dat11, test.dat22 etc are present in the source dir. However, this statement is checking only... (2 Replies)
Discussion started by: sweety123
2 Replies

7. Programming

File Pattern Matching C++

Hi, I have large files with fixed length fields or fields seperated by delimeter. I would like to do validation on some or all fields to check for numeric or date or characters etc.. I would like to write this in C++. Please let me know if any one have any ideas on this. Thanks for all... (2 Replies)
Discussion started by: rameshmelam
2 Replies

8. Shell Programming and Scripting

Pattern matching for file

Hi All, I'm new to perl, My requirement is to check if particular file exists. e.g. filename.txt, filename1.txt, filename2.txt etc I tried the below code:- my $var1 = "filename.txt" if ( -e ($var1 = ~ /file\w/)) { print "File found \n"; } else { print "File not found \n"; } ... (0 Replies)
Discussion started by: doitnow
0 Replies

9. AIX

View lastest content in the file

Hi, May i know how can i view the lastest content of the log file. Currently, i use the "more" command : more logfile However, it will give me the content last year first and i had to keep using the space bar to move down to the lastest content for current date. How can i view the lastest... (3 Replies)
Discussion started by: Lauran Kerry
3 Replies

10. Programming

getting file words as pattern matching

Sir, I want to check for the repation of a user address in a file i used || as my delimiter and want to check repetaip0n of the address that is mailid and then i have to use IMAP and all. How can i do this... I am in linux ...and my file is linux file. ... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies
Login or Register to Ask a Question