If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > sorting file from grep result

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-22-08, 22:37
rei rei is offline
Registered User
 
Join Date: Jul 2004
Posts: 30
sorting file from grep result

I'm trying to do something like this.
(1) grep certain pattern from files, and print out the files which match the pattern
(2) sort the filename according to modified date

(1) $result = `grep -rl 'MYPATTERN' *`
(2) sorry... can anyone tells me how to sort this?
I've tried with grep -rl 'MYPATTERN' * | ls -tr but still it doesn't work
Reply With Quote
  #2 (permalink)  
Old 01-23-08, 01:51
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
ls -lrt `grep -l 'MYPATTERN' *`
Reply With Quote
  #3 (permalink)  
Old 01-23-08, 04:06
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Or:
Code:
grep -rl 'MYPATTERN' * | xargs ls -tr
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 01-23-08, 05:34
rei rei is offline
Registered User
 
Join Date: Jul 2004
Posts: 30
thanks pdreyer & stolze !!!

i must admit.. my unix is so poor...
thank you !!
Reply With Quote
  #5 (permalink)  
Old 01-23-08, 07:46
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,452
I think it will also work if you put it the other way around:
Code:
ls -ltr | xargs grep -l
So many ways to skin a cat...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On