Sort files by date in filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort files by date in filename
# 8  
Old 12-27-2011
Yes. In addition, as long as the ASCIIbetical order is good for you,
you don't even need the sort command:
Code:
zsh-4.3.14[t]% ls -1 IGL01*.dat 
IGL01_AC_D_20110614_N01_01.dat
IGL01_AC_D_20110614_N01_02.dat
IGL01_AC_D_20110614_N02_01.dat
IGL01_AC_D_20110615_N01_01.dat

This User Gave Thanks to radoulov For This Post:
# 9  
Old 12-28-2011
woohooo..thats really amazing. Smilie
I will surely play around with all these combinations of command to get a good feel.

Thank you lots very much. Nice to have people like you for helping us in these forums Smilie

---------- Post updated 12-28-11 at 01:46 AM ---------- Previous update was 12-27-11 at 05:31 PM ----------

Sorry to be here again..if im not too abusing on this forum Smilie

One question pop up in my mind last night.

what is the difference between the
Code:
-k4

and
Code:
-k4,4

Many Thanks
# 10  
Old 12-28-2011
Code:
 
man sort

# 11  
Old 12-28-2011
There is no substitute for testing things out yourself. Have a go and see what you get. It is simple enough to create a directory for testing and then use touch to create a bunch of files with the name in the correct format with enough variations to have a go with the code you have.


If there is more required, please show what you have tried and what your files are listed as and what you are trying to acheive. There are some subtle differences in the version of sort on some flavours of unix, so we might be breaking its rules somewhere.

Let us know how you get on.



Robin
Liverpool/Blackburn
UK
# 12  
Old 12-28-2011
I will try some and get back to you but nevertherless I'm really satisfied with the answers given in the forums here because the modification I made to my shell works well and is already on prod env Smilie

Big applause and thanks to you all. I will play around with some more command and get back soon. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort log files based on numeric value in the filename

Hi, I have a list of log files as follows: name_date_0001_ID0.log name_date_0001_ID2.log name_date_0001_ID1.log name_date_0002_ID2.log name_date_0004_ID0.log name_date_0005_ID0.log name_date_0021_ID0.log name_date_0025_ID0.log .......................................... (4 Replies)
Discussion started by: alex2005
4 Replies

2. Shell Programming and Scripting

Find files greater than a particular date in filename.

I need a unix command which will find all the files greater that a particular date in the file name. say for example I have files like(filenaming cov : filename.YYDDMMSSSS.txt) abc.201206015423.txt abc.201207013456.txt abc.201202011234.txt abc.201201024321.txt efg.201202011234.txt... (11 Replies)
Discussion started by: lijjumathew
11 Replies

3. Shell Programming and Scripting

Bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

4. Shell Programming and Scripting

URGENT!!! bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

5. UNIX for Dummies Questions & Answers

sort files by numeric filename

dear all, i have .dat files named as: 34.dat 2.dat 16.dat 107.dat i would like to sort them by their filenames as: 2.dat 16.dat 34.dat 107.dat i have tried numerous combinations of sort and ls command (in vain) to obtain : 107.dat 16.dat 2.dat 34.dat (1 Reply)
Discussion started by: chen.xiao.po
1 Replies

6. Shell Programming and Scripting

Move files based on date in filename

I know this gets covered quite a bit in the forum and I think there is enough there for me to figure out how to do what I am trying to do, I just don't think I would do it very efficiently so I am going to ask the question... I have database log files with date and time stamps in the file like ... (7 Replies)
Discussion started by: slatoms
7 Replies

7. UNIX for Dummies Questions & Answers

Sort files by date, not showing files from today

Hi all, i'm new here in this forum. I really like the helpful answers in this forum. Here a short question. For a script i have to sort files by date and exclude the files of the actual date. Sorting the files by date and preparing the output for awk is done by this line: ls -l... (3 Replies)
Discussion started by: carlosdivega
3 Replies

8. Linux

sort files by date

Hi All, Sorry to throw this frequent question but I lost my notes on it. How do you list the files by date? I'm on red hat. Thanks in advance, itik (1 Reply)
Discussion started by: itik
1 Replies

9. Shell Programming and Scripting

Sort files by Date-timestamps available in filename & pick the sortedfiles one by one

Hi, I am new to Unix shell scripting. Can you please help me with this immediate requirement to code.. The requirement is as given below. In a directory say Y, I have files like this. PP_100000_28062006_122731_746.dat PP_100000_28062006_122731_745.dat PP_100000_28062006_122734_745.dat... (4 Replies)
Discussion started by: Chindhu
4 Replies

10. UNIX for Dummies Questions & Answers

Renaming files to have date/time in filename

I have a program that will export my data to a single file, but it assigns a file name that is overridden every time I run the program. I need to change the file name to have a sequential number in the filename. How do I rename a file so that the filename contains the system date and time. I want... (5 Replies)
Discussion started by: wayneb
5 Replies
Login or Register to Ask a Question