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

Clash 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 !
awk grep find
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.
add a comment |Â
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 !
awk grep find
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 containsAAAbut no files that containBBB(even if they containAAA). What would you want to do with them? I'm confused by yourawkcommand.
â Kusalananda
Mar 7 at 14:33
add a comment |Â
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 !
awk grep find
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
awk grep find
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 containsAAAbut no files that containBBB(even if they containAAA). What would you want to do with them? I'm confused by yourawkcommand.
â Kusalananda
Mar 7 at 14:33
add a comment |Â
I'm not sure I understand. You want to find all files that containsAAAbut no files that containBBB(even if they containAAA). What would you want to do with them? I'm confused by yourawkcommand.
â 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
add a comment |Â
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
@kusalanada : I would like to extract some word just afterAAAin fact because I have something likeAAA = xxx;and I want to provide a list with xxx and file path to know for wich AAABBBpart is missing !
â Delphine
Mar 7 at 15:10
1
Finally I used thisfind /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.txtwhereAAAis in realityconst TABLE_NAME:)
â Delphine
Mar 7 at 15:18
add a comment |Â
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
add a comment |Â
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
add a comment |Â
up vote
0
down vote
find .... -name '*.php'
-exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out
add a comment |Â
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
@kusalanada : I would like to extract some word just afterAAAin fact because I have something likeAAA = xxx;and I want to provide a list with xxx and file path to know for wich AAABBBpart is missing !
â Delphine
Mar 7 at 15:10
1
Finally I used thisfind /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.txtwhereAAAis in realityconst TABLE_NAME:)
â Delphine
Mar 7 at 15:18
add a comment |Â
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
@kusalanada : I would like to extract some word just afterAAAin fact because I have something likeAAA = xxx;and I want to provide a list with xxx and file path to know for wich AAABBBpart is missing !
â Delphine
Mar 7 at 15:10
1
Finally I used thisfind /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.txtwhereAAAis in realityconst TABLE_NAME:)
â Delphine
Mar 7 at 15:18
add a comment |Â
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
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
answered Mar 7 at 14:36
Kusalananda
103k13202318
103k13202318
@kusalanada : I would like to extract some word just afterAAAin fact because I have something likeAAA = xxx;and I want to provide a list with xxx and file path to know for wich AAABBBpart is missing !
â Delphine
Mar 7 at 15:10
1
Finally I used thisfind /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.txtwhereAAAis in realityconst TABLE_NAME:)
â Delphine
Mar 7 at 15:18
add a comment |Â
@kusalanada : I would like to extract some word just afterAAAin fact because I have something likeAAA = xxx;and I want to provide a list with xxx and file path to know for wich AAABBBpart is missing !
â Delphine
Mar 7 at 15:10
1
Finally I used thisfind /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.txtwhereAAAis in realityconst 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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Mar 7 at 14:37
RomanPerekhrest
22.4k12144
22.4k12144
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited Mar 7 at 14:45
answered Mar 7 at 14:29
Gilles Quenot
15.3k13448
15.3k13448
add a comment |Â
add a comment |Â
up vote
0
down vote
find .... -name '*.php'
-exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out
add a comment |Â
up vote
0
down vote
find .... -name '*.php'
-exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out
add a comment |Â
up vote
0
down vote
up vote
0
down vote
find .... -name '*.php'
-exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out
find .... -name '*.php'
-exec awk -v RS="" '/AAA/ && !/BBB/print FILENAME' ; > out
answered Mar 7 at 17:24
JJoao
6,7011826
6,7011826
add a comment |Â
add a comment |Â
I'm not sure I understand. You want to find all files that contains
AAAbut no files that containBBB(even if they containAAA). What would you want to do with them? I'm confused by yourawkcommand.â Kusalananda
Mar 7 at 14:33