The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
concatenate files sorted by date docaia Shell Programming and Scripting 2 08-16-2008 03:23 AM
sort files by date itik Linux 1 06-02-2008 07:25 PM
Sort By Date and Time Raynon Shell Programming and Scripting 21 01-04-2008 09:50 AM
Sort by Date Mudshark Shell Programming and Scripting 2 04-18-2005 01:02 PM
Concatenate date to file name sierra_aar UNIX for Dummies Questions & Answers 4 02-14-2002 09:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-19-2008
jlarios jlarios is offline
Registered User
  
 

Join Date: May 2008
Posts: 3
sort by date and concatenate first three

Hi:
I am trying to create some script that sorts the files in a subdirectory by date and concatenates the thre most recently created files.
SAy,

file1 date1
file2 date2
file3 date3
file4 date4
file5 date5
file6 date6

i only want to concatenate the first three which are the most recently created files.

any help?
  #2 (permalink)  
Old 05-19-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,805

Code:
#!/bin/ksh
cat $( ls -rt file* | tail -3 ) > newfile

  #3 (permalink)  
Old 05-19-2008
jlarios jlarios is offline
Registered User
  
 

Join Date: May 2008
Posts: 3
Thank you for the code . it works however I did not think of the case where the system could go down and I could have 6 or x files to read.

Hence, how would I get the files that are yesterday's only even if they are mixed up with older-than-yesterday files?

Thank you
  #4 (permalink)  
Old 05-19-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,805
one way

Code:
cat $(find . -name 'file*'  -mtime -2) > /path/to/newfile

  #5 (permalink)  
Old 05-19-2008
jlarios jlarios is offline
Registered User
  
 

Join Date: May 2008
Posts: 3
Thumbs up

Thank you very much Jim; that mtime function(?) is what I was looking for.
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0