LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help sorting large number of files by timestamp and then greping those files (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-sorting-large-number-of-files-by-timestamp-and-then-greping-those-files-856115/)

scottjn 01-13-2011 11:22 AM

Need help sorting large number of files by timestamp and then greping those files
 
Hello all, I sincerely apologize if this question has been asked before but after searching the forums (and a couple of hours of Googling) I have found some clues but nothing that quite addresses the specific problem I have or helps me connect the various pieces.

I have a directory with over 100,000 files in it that I need to grep in order of timestamp. ls doesn't work of course because of the "argument list too long" problem. So far what I have been trying is to use find and then pipe that output into sort, and then finally pipe that into grep but have had no real success so far. After looking through the man page for sort I still can't find a timestamp related option. And unfortunately my filenames are no help (at least as far as I can tell), since they increment by single digits (e.g. xxx_0,xxx_1,xxx_2,...,xxx_10,...,xxx_10000).

Has any one tackled this sort (pun definitely intended :D) of issue before?

Thanks in advance for any help you can provide!

szboardstretcher 01-13-2011 01:01 PM

Code:

ls -ltr

scottjn 01-13-2011 01:32 PM

Quote:

Originally Posted by szboardstretcher (Post 4223266)
Code:

ls -ltr

OK, ls -ltr (which I am already familiar with) gives me a long list of files sorted by timestamp. How can I get grep to operate on the files output by ls -ltr in order of their timestamp?

Tinkster 01-13-2011 02:13 PM

Code:

for i in $( ls -ltr ); do grep "search term" $i; done


Cheers,
Tink

scottjn 01-14-2011 10:42 AM

Quote:

Originally Posted by Tinkster (Post 4223352)
Code:

for i in $( ls -ltr ); do grep "search term" $i; done


Cheers,
Tink

Hi Tink, thanks very much for your help! Using your code I was able write a working script that does exactly what I intended. That "i in $( ls -ltr )" bit is going to be immensely helpful in my work, since so much of my data is in ASCII format in tens or hundreds of thousands of files. Thanks again for your assistance!


All times are GMT -5. The time now is 09:28 PM.