listing Directory chronologically based on part of file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting listing Directory chronologically based on part of file name
# 1  
Old 11-10-2010
listing Directory chronologically based on part of file name

hi Everbody,

I had file names as shown
Code:
file_01_20101104.txt
file_01_20101105.txt
file_02_20101104.txt
file_01_20101205.txt
file_03_20101104.txt
file_02_20101105.txt

Now i want to list them based on the date in the file name as shown...
Code:
file_01_20101104.txt
file_02_20101104.txt
file_03_20101104.txt
file_01_20101105.txt
file_02_20101105.txt
file_01_20101205.txt

i cant do it by using the regular ls -ltr as it was sort in the chronologically based on the file creation time ....
can we do it using a single line UNIX command as i have to pass this command to another java program call...

Help is greatly appreciated....

Thanks in advance..

Reddy

Last edited by Scott; 11-10-2010 at 02:00 PM.. Reason: Code tags
# 2  
Old 11-10-2010
Try:
Code:
ls | sort -nt_ -k3,3 -k2,2

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 11-10-2010
Thats Awesome...
Perfectly working..

Now can you please explain me the command issued using sort.....
# 4  
Old 11-10-2010
-nsort numerically
-t_ use _ as field separator
-k3,3first use field 3
-k2,2and then use field 2

Last edited by Scrutinizer; 11-10-2010 at 03:10 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help with listing file name and modified date on a huge directory

hi, We have a huge directory that ha 5.1 Million files in it. We are trying to get the file name and modified timestamp of the most recent 3 years from this huge directory for a migration project. However, the ls command (background process) to list the file names and timestamp is running for... (2 Replies)
Discussion started by: subbu
2 Replies

2. UNIX for Beginners Questions & Answers

Listing a file/directory with 7 letters long

I know that I can use wild cards:ls ???????to list files 7 characters long, but how do i omit the .?! and spaces? Please use CODE tags when displaying sample input, sample output, and code segments. (2 Replies)
Discussion started by: hiya54
2 Replies

3. Shell Programming and Scripting

Discard part of a file based on a pattern ---

I have the file: s3_T0(2) Pos "1" "2" s1_T1(2) Pos "1" "2" --- 0 0 1 0 0 1 1 1 --- 1 2 "tau0" 1 2 "h10" I want to patternmatch on --- and get only the third part i.e. 1 2 "tau0" 1 2 "h10" I wanted to start simple but even something like (5 Replies)
Discussion started by: eagle_fly
5 Replies

4. Shell Programming and Scripting

Grep a part of file based on string identifiers

consider below file contents cat myOutputFIle.txt 8 CCM-HQE-ResourceHealthCheck: Resource List : No RED/UNKNOWN resource Health entries found ---------------------------------------------------------- 9 CCM-TraderLogin-Status: Number of logins: 0... (4 Replies)
Discussion started by: vivek d r
4 Replies

5. Shell Programming and Scripting

Remove part of a file based on identifiers

here below is a part of the file cat fileName.txt NAME=APP-VA-va_mediaservices-113009-VA_MS_MEDIA_SERVER_NOT_PRESENT-S FIXED=false DATE= 2013-02-19 03:46:04.4 PRIORITY=HIGH RESOURCE NAME=ccm113 NAME=APP-DS-ds_ha-140020-databaseReplicationFailure-S FIXED=false DATE= 2013-02-19... (4 Replies)
Discussion started by: vivek d r
4 Replies

6. Shell Programming and Scripting

Looping inside directories based on a file which contains file directory list

Hi All, Please help. I have got a file which contains a listing of a file and some directories after it, one by one. I am calling this file xyz.txt here file1 dir1 dir2 dir3 dir4 file2 dir5 dir6 dir7 dir8 file3 dir9 dir10 dir11 dir12 (6 Replies)
Discussion started by: Piyush Jakra
6 Replies

7. UNIX for Dummies Questions & Answers

File Listing from remote to loca directory using SFTP

Hello, Using ftp i was able to get a directory listing to local directory. ftp - i <host_name> ftp <user> ftp <password> dir <dir> 200 PORT command successful 150 Opening ASCII mode data connection for file list -rw-rw-r-- 1 <uuu> <kkk> 160384 Apr 13 19:38 walmart.txt 226... (5 Replies)
Discussion started by: pavan_test
5 Replies

8. UNIX for Dummies Questions & Answers

File listing from remote to local directory

Hello, I have a file at remote server. I have to select only current day's files that are dropped on ftp server. The files do not have date or timestamp on them. so I plan to get the file listing from remote server to the local server. Based on file listing date I can find out when the files... (2 Replies)
Discussion started by: pavan_test
2 Replies

9. UNIX for Dummies Questions & Answers

Remove part of file names in a directory

Hi, i have a directory full of pictures, .jpg files. Half of them begin with "beach_" (for ex beach_123_123456.jpg) i'm looking for a command to remove the "beach_" from all files in the directory. thanks (4 Replies)
Discussion started by: robertmanalio
4 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question