Find with two grep (contains AND not contains) and one awk [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • Find files that contain a string and do not contain another [duplicate]

    4 answers



I would like to store in file all path files with a specific extract of file content where file contains AAA but NOT BBB.



I tried so many things but this try is close to my goal :



find /data/my_project -type f -name "*.php" -exec grep -q "AAA" ; -exec grep -L "BBB" ; -exec awk '/AAA/print $NF'> /tmp/tables_names.txt ; -print > /tmp/class_list.txt


But... Result contains file with sometimes AAA only, AAA AND BBB..



EDIT :



This is pretty same question as Find files that contain a string and do not contain another but where there's no answer validated it was really difficult to read.
75 % of my answer was in fact there sorry...
But, I would like to return not only matched files paths but an extract (piece of text) of this matched file !







share|improve this question














marked as duplicate by don_crissti, G-Man, roaima, elbarna, Timothy Martin Mar 9 at 17:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I'm not sure I understand. You want to find all files that contains AAA but no files that contain BBB (even if they contain AAA). What would you want to do with them? I'm confused by your awk command.
    – Kusalananda
    Mar 7 at 14:33















up vote
0
down vote

favorite













This question already has an answer here:



  • Find files that contain a string and do not contain another [duplicate]

    4 answers



I would like to store in file all path files with a specific extract of file content where file contains AAA but NOT BBB.



I tried so many things but this try is close to my goal :



find /data/my_project -type f -name "*.php" -exec grep -q "AAA" ; -exec grep -L "BBB" ; -exec awk '/AAA/print $NF'> /tmp/tables_names.txt ; -print > /tmp/class_list.txt


But... Result contains file with sometimes AAA only, AAA AND BBB..



EDIT :



This is pretty same question as Find files that contain a string and do not contain another but where there's no answer validated it was really difficult to read.
75 % of my answer was in fact there sorry...
But, I would like to return not only matched files paths but an extract (piece of text) of this matched file !







share|improve this question














marked as duplicate by don_crissti, G-Man, roaima, elbarna, Timothy Martin Mar 9 at 17:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I'm not sure I understand. You want to find all files that contains AAA but no files that contain BBB (even if they contain AAA). What would you want to do with them? I'm confused by your awk command.
    – Kusalananda
    Mar 7 at 14:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • Find files that contain a string and do not contain another [duplicate]

    4 answers



I would like to store in file all path files with a specific extract of file content where file contains AAA but NOT BBB.



I tried so many things but this try is close to my goal :



find /data/my_project -type f -name "*.php" -exec grep -q "AAA" ; -exec grep -L "BBB" ; -exec awk '/AAA/print $NF'> /tmp/tables_names.txt ; -print > /tmp/class_list.txt


But... Result contains file with sometimes AAA only, AAA AND BBB..



EDIT :



This is pretty same question as Find files that contain a string and do not contain another but where there's no answer validated it was really difficult to read.
75 % of my answer was in fact there sorry...
But, I would like to return not only matched files paths but an extract (piece of text) of this matched file !







share|improve this question















This question already has an answer here:



  • Find files that contain a string and do not contain another [duplicate]

    4 answers



I would like to store in file all path files with a specific extract of file content where file contains AAA but NOT BBB.



I tried so many things but this try is close to my goal :



find /data/my_project -type f -name "*.php" -exec grep -q "AAA" ; -exec grep -L "BBB" ; -exec awk '/AAA/print $NF'> /tmp/tables_names.txt ; -print > /tmp/class_list.txt


But... Result contains file with sometimes AAA only, AAA AND BBB..



EDIT :



This is pretty same question as Find files that contain a string and do not contain another but where there's no answer validated it was really difficult to read.
75 % of my answer was in fact there sorry...
But, I would like to return not only matched files paths but an extract (piece of text) of this matched file !





This question already has an answer here:



  • Find files that contain a string and do not contain another [duplicate]

    4 answers









share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 15:24

























asked Mar 7 at 14:22









Delphine

1033




1033




marked as duplicate by don_crissti, G-Man, roaima, elbarna, Timothy Martin Mar 9 at 17:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by don_crissti, G-Man, roaima, elbarna, Timothy Martin Mar 9 at 17:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • I'm not sure I understand. You want to find all files that contains AAA but no files that contain BBB (even if they contain AAA). What would you want to do with them? I'm confused by your awk command.
    – Kusalananda
    Mar 7 at 14:33

















  • I'm not sure I understand. You want to find all files that contains AAA but no files that contain BBB (even if they contain AAA). What would you want to do with them? I'm confused by your awk command.
    – Kusalananda
    Mar 7 at 14:33
















I'm not sure I understand. You want to find all files that contains AAA but no files that contain BBB (even if they contain AAA). What would you want to do with them? I'm confused by your awk command.
– Kusalananda
Mar 7 at 14:33





I'm not sure I understand. You want to find all files that contains AAA but no files that contain BBB (even if they contain AAA). What would you want to do with them? I'm confused by your awk command.
– Kusalananda
Mar 7 at 14:33











4 Answers
4






active

oldest

votes

















up vote
4
down vote



accepted










Finding all regular files with filenames matching *.php in or below /data/my_project that contain AAA but not BBB and storing their pathnames in /tmp/class_list.txt:



find /data/my_project -type f -name '*.php' 
-exec grep -qF 'AAA' ';'
! -exec grep -qF 'BBB' ';'
-print >/tmp/class_list.txt





share|improve this answer




















  • @kusalanada : I would like to extract some word just after AAA in fact because I have something like AAA = xxx; and I want to provide a list with xxx and file path to know for wich AAA BBB part is missing !
    – Delphine
    Mar 7 at 15:10






  • 1




    Finally I used this find /data/my_project -type f -name '*.php' -exec grep -qF 'const TABLE_NAME' ';' ! -exec grep -qF 'BBB' ';' -exec awk '/const TABLE_NAME/print $NF' ';' -print >/tmp/class_list.txt where AAA is in reality const TABLE_NAME :)
    – Delphine
    Mar 7 at 15:18

















up vote
2
down vote













find + awk solution:



find /data/my_project -type f -name "*.php" -exec 
awk '/AAA/ a=1 /BBB/ b=1 END' ; -print > /tmp/class_list.txt





share|improve this answer



























    up vote
    1
    down vote













    Try this :



    find /data/my_project -type f -name '*.php' -exec 
    bash -c 'grep -q AAA "$1" && ! grep -q BBB "$1" && echo "$1"' -- ;
    > /tmp/class_list.txt





    share|improve this answer





























      up vote
      0
      down vote













      find .... -name '*.php' 
      -exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out





      share|improve this answer



























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        4
        down vote



        accepted










        Finding all regular files with filenames matching *.php in or below /data/my_project that contain AAA but not BBB and storing their pathnames in /tmp/class_list.txt:



        find /data/my_project -type f -name '*.php' 
        -exec grep -qF 'AAA' ';'
        ! -exec grep -qF 'BBB' ';'
        -print >/tmp/class_list.txt





        share|improve this answer




















        • @kusalanada : I would like to extract some word just after AAA in fact because I have something like AAA = xxx; and I want to provide a list with xxx and file path to know for wich AAA BBB part is missing !
          – Delphine
          Mar 7 at 15:10






        • 1




          Finally I used this find /data/my_project -type f -name '*.php' -exec grep -qF 'const TABLE_NAME' ';' ! -exec grep -qF 'BBB' ';' -exec awk '/const TABLE_NAME/print $NF' ';' -print >/tmp/class_list.txt where AAA is in reality const TABLE_NAME :)
          – Delphine
          Mar 7 at 15:18














        up vote
        4
        down vote



        accepted










        Finding all regular files with filenames matching *.php in or below /data/my_project that contain AAA but not BBB and storing their pathnames in /tmp/class_list.txt:



        find /data/my_project -type f -name '*.php' 
        -exec grep -qF 'AAA' ';'
        ! -exec grep -qF 'BBB' ';'
        -print >/tmp/class_list.txt





        share|improve this answer




















        • @kusalanada : I would like to extract some word just after AAA in fact because I have something like AAA = xxx; and I want to provide a list with xxx and file path to know for wich AAA BBB part is missing !
          – Delphine
          Mar 7 at 15:10






        • 1




          Finally I used this find /data/my_project -type f -name '*.php' -exec grep -qF 'const TABLE_NAME' ';' ! -exec grep -qF 'BBB' ';' -exec awk '/const TABLE_NAME/print $NF' ';' -print >/tmp/class_list.txt where AAA is in reality const TABLE_NAME :)
          – Delphine
          Mar 7 at 15:18












        up vote
        4
        down vote



        accepted







        up vote
        4
        down vote



        accepted






        Finding all regular files with filenames matching *.php in or below /data/my_project that contain AAA but not BBB and storing their pathnames in /tmp/class_list.txt:



        find /data/my_project -type f -name '*.php' 
        -exec grep -qF 'AAA' ';'
        ! -exec grep -qF 'BBB' ';'
        -print >/tmp/class_list.txt





        share|improve this answer












        Finding all regular files with filenames matching *.php in or below /data/my_project that contain AAA but not BBB and storing their pathnames in /tmp/class_list.txt:



        find /data/my_project -type f -name '*.php' 
        -exec grep -qF 'AAA' ';'
        ! -exec grep -qF 'BBB' ';'
        -print >/tmp/class_list.txt






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 14:36









        Kusalananda

        103k13202318




        103k13202318











        • @kusalanada : I would like to extract some word just after AAA in fact because I have something like AAA = xxx; and I want to provide a list with xxx and file path to know for wich AAA BBB part is missing !
          – Delphine
          Mar 7 at 15:10






        • 1




          Finally I used this find /data/my_project -type f -name '*.php' -exec grep -qF 'const TABLE_NAME' ';' ! -exec grep -qF 'BBB' ';' -exec awk '/const TABLE_NAME/print $NF' ';' -print >/tmp/class_list.txt where AAA is in reality const TABLE_NAME :)
          – Delphine
          Mar 7 at 15:18
















        • @kusalanada : I would like to extract some word just after AAA in fact because I have something like AAA = xxx; and I want to provide a list with xxx and file path to know for wich AAA BBB part is missing !
          – Delphine
          Mar 7 at 15:10






        • 1




          Finally I used this find /data/my_project -type f -name '*.php' -exec grep -qF 'const TABLE_NAME' ';' ! -exec grep -qF 'BBB' ';' -exec awk '/const TABLE_NAME/print $NF' ';' -print >/tmp/class_list.txt where AAA is in reality const TABLE_NAME :)
          – Delphine
          Mar 7 at 15:18















        @kusalanada : I would like to extract some word just after AAA in fact because I have something like AAA = xxx; and I want to provide a list with xxx and file path to know for wich AAA BBB part is missing !
        – Delphine
        Mar 7 at 15:10




        @kusalanada : I would like to extract some word just after AAA in fact because I have something like AAA = xxx; and I want to provide a list with xxx and file path to know for wich AAA BBB part is missing !
        – Delphine
        Mar 7 at 15:10




        1




        1




        Finally I used this find /data/my_project -type f -name '*.php' -exec grep -qF 'const TABLE_NAME' ';' ! -exec grep -qF 'BBB' ';' -exec awk '/const TABLE_NAME/print $NF' ';' -print >/tmp/class_list.txt where AAA is in reality const TABLE_NAME :)
        – Delphine
        Mar 7 at 15:18




        Finally I used this find /data/my_project -type f -name '*.php' -exec grep -qF 'const TABLE_NAME' ';' ! -exec grep -qF 'BBB' ';' -exec awk '/const TABLE_NAME/print $NF' ';' -print >/tmp/class_list.txt where AAA is in reality const TABLE_NAME :)
        – Delphine
        Mar 7 at 15:18












        up vote
        2
        down vote













        find + awk solution:



        find /data/my_project -type f -name "*.php" -exec 
        awk '/AAA/ a=1 /BBB/ b=1 END' ; -print > /tmp/class_list.txt





        share|improve this answer
























          up vote
          2
          down vote













          find + awk solution:



          find /data/my_project -type f -name "*.php" -exec 
          awk '/AAA/ a=1 /BBB/ b=1 END' ; -print > /tmp/class_list.txt





          share|improve this answer






















            up vote
            2
            down vote










            up vote
            2
            down vote









            find + awk solution:



            find /data/my_project -type f -name "*.php" -exec 
            awk '/AAA/ a=1 /BBB/ b=1 END' ; -print > /tmp/class_list.txt





            share|improve this answer












            find + awk solution:



            find /data/my_project -type f -name "*.php" -exec 
            awk '/AAA/ a=1 /BBB/ b=1 END' ; -print > /tmp/class_list.txt






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 7 at 14:37









            RomanPerekhrest

            22.4k12144




            22.4k12144




















                up vote
                1
                down vote













                Try this :



                find /data/my_project -type f -name '*.php' -exec 
                bash -c 'grep -q AAA "$1" && ! grep -q BBB "$1" && echo "$1"' -- ;
                > /tmp/class_list.txt





                share|improve this answer


























                  up vote
                  1
                  down vote













                  Try this :



                  find /data/my_project -type f -name '*.php' -exec 
                  bash -c 'grep -q AAA "$1" && ! grep -q BBB "$1" && echo "$1"' -- ;
                  > /tmp/class_list.txt





                  share|improve this answer
























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Try this :



                    find /data/my_project -type f -name '*.php' -exec 
                    bash -c 'grep -q AAA "$1" && ! grep -q BBB "$1" && echo "$1"' -- ;
                    > /tmp/class_list.txt





                    share|improve this answer














                    Try this :



                    find /data/my_project -type f -name '*.php' -exec 
                    bash -c 'grep -q AAA "$1" && ! grep -q BBB "$1" && echo "$1"' -- ;
                    > /tmp/class_list.txt






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 7 at 14:45

























                    answered Mar 7 at 14:29









                    Gilles Quenot

                    15.3k13448




                    15.3k13448




















                        up vote
                        0
                        down vote













                        find .... -name '*.php' 
                        -exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out





                        share|improve this answer
























                          up vote
                          0
                          down vote













                          find .... -name '*.php' 
                          -exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out





                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            find .... -name '*.php' 
                            -exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out





                            share|improve this answer












                            find .... -name '*.php' 
                            -exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 7 at 17:24









                            JJoao

                            6,7011826




                            6,7011826












                                Popular posts from this blog

                                Peggy Mitchell

                                Palaiologos

                                The Forum (Inglewood, California)