Results 1 to 3 of 3

Thread: grep help

  1. #1
    Senior Member
    Join Date
    Jan 2006
    Location
    Oop North
    Posts
    1,403
    Thanks
    2
    Thanked
    4 times in 4 posts

    grep help

    Hi

    Does anyone know how to use grep to return the number of files in a directory that contain the search string? I can get it to return the lines that match, but not the number. I've used:

    grep -c /usr/bin/*a* > outputfile

    This returns all the lines that match and writes them to outputfile, but I need the number of matches.

    Thanks

  2. #2
    Agent of the System ikonia's Avatar
    Join Date
    May 2004
    Location
    South West UK (Bath)
    Posts
    3,736
    Thanks
    39
    Thanked
    75 times in 56 posts

    Re: grep help

    greps not the right tool for the job as its looking for a regular expresion to which the char "a" is not.

    you want

    Code:
    ls /usr/bin/*a* | wc -l
    or you can do something weak with grep, but it won't give you the results you want, but I'll put it to show how using grep is the wrong tool

    Code:
    grep -c a /usr/bin/*
    or a dirty fugde

    Code:
    ls /usr/bin/*a* | grep -c a
    the last two are just to show that grep is the wrong tool for the job and how your miss-interperating its use.
    It is Inevitable.....


  3. #3
    Senior Member
    Join Date
    Jan 2006
    Location
    Oop North
    Posts
    1,403
    Thanks
    2
    Thanked
    4 times in 4 posts

    Re: grep help

    Ah, thanks for the help. I'd forgotten about wc. Have been sat here for the past hour trying to get grep to work, and searching the Internet for the answer

    Cheers

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 20
    Last Post: 17-04-2007, 09:31 PM

Posting Permissions

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