LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-13-2011, 11:22 AM   #1
scottjn
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Rep: Reputation: 0
Question 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 ) of issue before?

Thanks in advance for any help you can provide!

Last edited by scottjn; 01-13-2011 at 11:23 AM. Reason: Typo in subject line
 
Old 01-13-2011, 01:01 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Code:
ls -ltr
 
Old 01-13-2011, 01:32 PM   #3
scottjn
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by szboardstretcher View Post
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?
 
Old 01-13-2011, 02:13 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
for i in $( ls -ltr ); do grep "search term" $i; done


Cheers,
Tink

Last edited by Tinkster; 01-13-2011 at 02:14 PM.
 
1 members found this post helpful.
Old 01-14-2011, 10:42 AM   #5
scottjn
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post
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!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Updating timestamp in files in directory tuxtutorials Programming 5 08-21-2010 09:03 AM
join 2 text files based on first number present in every line of the 2 text files markraem Linux - Software 4 01-25-2010 06:26 AM
Retrieving timestamp of oracle files using shell scripts jain_sanad Programming 1 04-10-2008 02:51 PM
script to sort files according to timestamp aeby Linux - Newbie 1 05-16-2007 08:18 AM
Files being created with GMT timestamp Locura Slackware 0 12-07-2004 08:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration