sort by date and concatenate first three


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sort by date and concatenate first three
# 1  
Old 05-19-2008
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  
Old 05-19-2008
Code:
#!/bin/ksh
cat $( ls -rt file* | tail -3 ) > newfile

# 3  
Old 05-19-2008
Thank you for the code Smilie. 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  
Old 05-19-2008
one way
Code:
cat $(find . -name 'file*'  -mtime -2) > /path/to/newfile

# 5  
Old 05-19-2008
MySQL

Thank you very much Jim; that mtime function(?) is what I was looking for.SmilieSmilieSmilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenate and sort to remove duplicates

Following is the input. 1st and 3rd block are same(block starts here with '*' and ends before blank line) , 2nd and 4th blocks are also the same: cat <file> * Wed Feb 24 2016 Tariq Saeed <tariq.x.saeed@mail.com> 2.0.7-1.0.7 - add vmcore dump support for ocfs2 * Mon Jun 8 2015 Brian Maly... (4 Replies)
Discussion started by: Paras Pandey
4 Replies

2. Shell Programming and Scripting

Sort by name and date

nawk '$1=="Date" {d=$(NF-2);next} $1=="Queue" {q=$NF;next} $1=="Forms"{print q, $NF, d}' OFS='|' printfile.log I have this script working. Please let me know how to sort by Queue and then Date. (4 Replies)
Discussion started by: Daniel Gate
4 Replies

3. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

4. Shell Programming and Scripting

Concatenate many files which contents the same date as part of name file

Gents, I have lot of files in a folder where each file name includes the date of generation, then I would like to merge all the files for each date in a complete file. list of files in forder. dsd01_121104.txt dsd01_121105.txt dsd01_121106.txt dsd03_121104.txt dsd03_121105.txt... (7 Replies)
Discussion started by: jiam912
7 Replies

5. Shell Programming and Scripting

sort the date

Hi All, Please help me to sort the date field which is in the format 2012-02-03 16:09:37.388... Platform: Red Hat linux Thanks in advance (2 Replies)
Discussion started by: jesu
2 Replies

6. Shell Programming and Scripting

how to sort by the date

Hello World~ Please Help Me(BASH) input: dde,2007.8.25,891 dde,2007.8.23,356 dfe,2007.10.12,341 cba,2005.12.5,342 I wanna know how to sort by the date(2005.12.5) output: cba,2005.12.5,342 dde,2007.8.23,356 dde,2007.8.25,891 dfe,2007.10.12,341 Thanks in advance (3 Replies)
Discussion started by: lifegeek
3 Replies

7. Shell Programming and Scripting

concatenate files sorted by date

I am a beginner in script writing, i tried to do the following I have a set of files sorted by date in the format YYMMDD.s and .x and .r I need to concatenate a header file to these sets of files so I used the following code echo "enter Swath number" read s echo "please enter first date and... (2 Replies)
Discussion started by: docaia
2 Replies

8. Solaris

concatenate/sort/cut

I have the following requirement. 1. I have to concatenate the 10 fixed width files. 2. sort based on first 10 characters 3. after that i have remove first 10 chacters from the file. can you please tell me how to do it. Thanks in Advance Samba (1 Reply)
Discussion started by: samba
1 Replies

9. Shell Programming and Scripting

Sort by Date

I'm looking to edit a file which contains various data including date.(ddmmyyyy) I want to sort by date and then count the number of different dates found Any ideas how to acheive this Thanks in advance. (2 Replies)
Discussion started by: Mudshark
2 Replies

10. UNIX for Dummies Questions & Answers

Concatenate date to file name

Hi, I have written a script to rename a file, but I can not add the current date (in YYYYMMDD-HHMM format) can you please look at this cript, and help? thanks, #!/usr/local/bin/tcsh -f set server = "$1" set user = "$2" if (-f $server) then \mv $server $server.Saar. endif (4 Replies)
Discussion started by: sierra_aar
4 Replies
Login or Register to Ask a Question