UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 19th, 2006, 09:50 PM
svvc svvc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 12 svvc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 20 m 58 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old February 20th, 2006, 02:05 PM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 815 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 36 m 20 sec
Reputation Power: 243
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Sorting the files from multiple directories by timestamp


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT