Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

find with grep - not matching strings

  • 19-06-2007 10:39AM
    #1
    Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭


    Right, I'm trying to find all the files in a directory which DONT contain a certain search term. This is in bash btw. (Cygwin actually.. yes I know, dont hate me, hate the machine..)
    find . -name "*.htm" -exec grep -vq "foo" '{}' \; -print
    

    is not working. What am I doing wrong..?


Comments

  • Closed Accounts Posts: 97 ✭✭koloughlin


    It looks like there's something wrong with grep -qv. Check this out:
    [user@box ~]$ grep -qv "infile" file.txt
    [user@box ~]$ echo $?
    0
    [user@box ~]$ grep -q "infile" file.txt
    [user@box ~]$ echo $?
    0
    [user@box ~]$ grep -qv "notinfile" file.txt
    [user@box ~]$ echo $?
    0
    [user@box ~]$ grep -q "notinfile" file.txt
    [user@box ~]$ echo $?
    1
    

    I would have expected the first case above to return a 1 return code since infile is in file.txt, but it didn't work as expected. Feature or bug, who knows?

    Could you just use grep?
    grep -RL "foo" *.htm
    


  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    Hmm, that doesnt seem to recurse?!

    Funny.. or not..


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    do pipes work on cygwin?

    find . -name "*.htm" | grep -v <pattern>


  • Closed Accounts Posts: 97 ✭✭koloughlin


    Khannie wrote:
    do pipes work on cygwin?

    find . -name "*.htm" | grep -v <pattern>

    Wouldn't that search the path and filename, rather than actually open the file and search the contents of the file?

    I'm pretty sure
    grep -RL "foo" *.htm
    
    will work. I tried it in cygwin and it does recurse through the filesystem.


Advertisement