• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

command to cat all *.dat files except ones modified today.

Title kind of says it all.  I need to execute the concatenate command against all .dat files in the directory except those that have been modified today.  So today is 12/09/11, this means the command should concatenate all except the last one in the list below.

$ ls -ltr *.dat
-rw-r--r-- 1 initiate initgrp  136 Nov 18 15:07 input-20111118-1507.dat
-rw-r--r-- 1 initiate initgrp  180 Nov 18 16:17 input-20111118-1617.dat
-rw-r--r-- 1 initiate initgrp   80 Nov 18 16:26 input-20111118-1626.dat
-rw-r--r-- 1 initiate initgrp  121 Nov 18 16:43 input-20111118-1643.dat
-rw-r--r-- 1 initiate initgrp 1079 Nov 18 17:50 input-20111118-1734.dat
-rw-r--r-- 1 initiate initgrp  602 Dec  7 12:02 input-20111207-1202.dat
-rw-r--r-- 1 initiate initgrp  173 Dec  7 12:21 input-20111207-1221.dat
-rw-r--r-- 1 initiate initgrp  348 Dec  9 14:53 input-20111209-1256.dat
0
donnatronious
Asked:
donnatronious
  • 4
  • 2
2 Solutions
 
donnatroniousAuthor Commented:
Forgot to mention I'm using korn shell on RHLE 5.5 :-)
0
 
xtermCommented:
This should work.  Let me know if you want to do more than that.
find . -type f -name "*.dat" -mtime 1 | xargs cat

Open in new window

0
 
xtermCommented:
You can replace "." in the command with /path/to/files if you're running it from somewhere other than the directory containing the files.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
xtermCommented:
Yikes, I should learn to read.  I didn't see the "except" today.  Here, do this instead.  The +1 says to only search for files modified more than 1 day ago.
find /path/to/files -type f -name "*.dat" -mtime +1 | xargs cat

Open in new window

0
 
Kamaraj SubramanianApplication Support AnalystCommented:
find /path -type f -name "*.dat" -mtime +1 | while read file; do cat $file >> /tmp/output.txt; done

Open in new window

0
 
donnatroniousAuthor Commented:
xterm,

This works,

find /path/to/files -type f -name "*.dat" -mtime +1 | xargs cat

except its putting the last file modified first in the output.  It should cat them in the same order that a ls -l displays them.

Thanks in advance.
0
 
xtermCommented:
hmm, try this:
ls -ltra `find . -type f -name "*.php"` | awk '{print $9}' | xargs cat

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now