Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    30

    Unanswered: 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

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    ls -lrt `grep -l 'MYPATTERN' *`

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Or:
    Code:
    grep -rl 'MYPATTERN' * | xargs ls -tr
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  4. #4
    Join Date
    Jul 2004
    Posts
    30
    thanks pdreyer & stolze !!!

    i must admit.. my unix is so poor...
    thank you !!

  5. #5
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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...
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •