Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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