Sorting file based on names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting file based on names
# 1  
Old 12-05-2011
Sorting file based on names

Hi
I have some files in directory and the names of files are like

Code:
jnhld_15233_2010-11-23
jnhld_15233_2007-10-01
jnhld_15233_2001-05-04
jnhld_15233_2011-11-11
jnhld_15233_2005-06-07
jnhld_15233_2000-04-01
..etc

How can i sort these files based on the date in the file name so that jnhld_15233_2000-04-01 come first and jnhld_15233_2011-11-11 comes last.

Last edited by radoulov; 12-05-2011 at 03:38 PM.. Reason: Code tags!
# 2  
Old 12-05-2011
If the date of the file matchs the file name you should be able to use "ls -r".
# 3  
Old 12-05-2011
No.The file name and date of file creation are different.They are not matching. Here I cant use ls -lrt . I need to sort based on name
# 4  
Old 12-05-2011
Code:
printf '%s\n' jnhld_* | sort -t_ -k3n

# 5  
Old 12-06-2011
wowwww.. Thanx a lot dude
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting based on File name

Hi All I have a requirement to list all the files in chronological order based on the date value in the file name.For ex if I have three files as given below ABC_TEST_20160103_1012.txt ABC_TEST_20160229_1112.txt ABC_TEST_20160229_1112.txt I have written code as given below to list out... (2 Replies)
Discussion started by: ginrkf
2 Replies

2. Shell Programming and Scripting

Sorting file based on a numeric column

Hi, I use UBUNTU 12.04. I have a file with this structure: Name 2 1245787 A G 12 14 12 14 .... Name 1 1245789 C T 13 12 12 12..... I would like to sort my file based on the second column so to have this output for example: Name 1 1245789 C T 13 12 12 12..... Name 2 1245787 A G 12 14... (4 Replies)
Discussion started by: Homa
4 Replies

3. Shell Programming and Scripting

Sorting file based on name

Hi team, We have few files landing to our server based on sequence number. These files have to be processed in the sequence number order. Once the sequence number has reached its maximum, the files with sequence number 0000 has to be processed. For example: IN9997 IN9998 IN9999 IN0000... (7 Replies)
Discussion started by: anijan
7 Replies

4. UNIX for Dummies Questions & Answers

Sorting a file based on the absolute value of a column

I would like to sort a tab delimited text file based on the absolute value of its second column. How do I go about doing that? Thanks! Example input: A -12 B 0 C -6 D 7 Output: A -12 D 7 C -6 B 0 (4 Replies)
Discussion started by: evelibertine
4 Replies

5. Shell Programming and Scripting

sorting file names with hyphen and underscore

Hi, I have two types of file names filename1_12345 or filename1-12345 at the same time I have second type filename2-12345 in a txt file. I am trying to write awk script that will sort these names with below pattern ALL file names like filename1_12345 and filename1-12345 will go to... (1 Reply)
Discussion started by: rider29
1 Replies

6. Shell Programming and Scripting

sorting based on a specified column in a text file

I have a tab delimited file with 5 columns 79 A B 20.2340 6.1488 8.5086 1.3838 87 A B 0.1310 0.0382 0.0054 0.1413 88 A B 46.1651 99.0000 21.8107 0.2203 89 A B 0.1400 0.1132 0.0151 0.1334 114 A B 0.1088 0.0522 0.0057 0.1083 115 A B... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

7. Shell Programming and Scripting

sorting file based on two or more columns

Hi gang. I'm using a unix/mac system and i'm trying to sort a file (more than 1,000,000 lines). chr1 100000965 100001001 - chr1 100002155 100002191 + chr1 100002165 100002201 + chr1 100002525 100002561 - chr1 10000364 ... (2 Replies)
Discussion started by: labrazil
2 Replies

8. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

9. Shell Programming and Scripting

Separate based on file names

Hello experts, This might prove to be a stupid question to some of you, but I have tried to tackle it in different ways. Being new to shell scripting, I am requesting your help in coming up with an elegant solution. I am using Korn shell. We have a directory with file names with the pattern:... (2 Replies)
Discussion started by: prashk15
2 Replies

10. UNIX for Dummies Questions & Answers

File names based off of wildcards

Hello all- First post, so just to forewarn you: I know enough about Perl and the Terminal to get myself into trouble, not quite enough to always get out. I'd like to know if it is possible to, from the command prompt, use a wild-card to declare the names of files for input and then use the... (1 Reply)
Discussion started by: tcquad
1 Replies
Login or Register to Ask a Question