|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sorting the files from multiple directories by timestamp
Hi,
I've two directories /home/folder1/ and /home/folder2/ There are multiple files under both the directories. I've to prepare a file which will have the list of the files from both the directories listed sorted by timestamp. Here is the case: /home/folder1/ has A1.txt date2 A2.txt date1 A3.txt date5 /home/folder2/ has A4.txt date3 A5.txt date4 A6.txt date6 I've to create a file output.txt which will have the contents as A2.txt date1 A1.txt date2 A4.txt date3 A5.txt date4 A3.txt date5 A6.txt date6 In order to achieve this i'm using ls and appending the contents onto one pre_output.txt file and sorting it on key which is the second field (date) For sorting i'm using sort -k 1,1M pre_output.txt > output.txt.....but somehow i'm not being successful...please suggest... Thanks in advance Sam |
|
#2
|
||||
|
||||
|
Oh, fun! Bear in mind that the time stamp visible from the OS is the modify time and that it will, if greater than quite a few months, change from being hh:mm with the month and day, to being the year, month and day (just cosmetic, but WILL affect your sort if you aim to use the displayed values).
If you just have recently modified files then you should think about how you want them sorted - yyyymmddhhmmss is generally a good way, thus you may need to construct that as a sort key: by passing the ls output through awk. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Sorting the files from multiple directories by timestamp |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|