grep all .asp file in specific directory that doesn't not contain a word

whm-expert

Active Member
Nov 10, 2012
40
0
6
cPanel Access Level
DataCenter Provider
hello
i want to make a bash script to grep all .asp file in specific directory that doesn't not contain a word like "program by x team" for security reason.

i mean if the grep command find these word"program by x team", it will ignore the file in result.

if the grep command doesnt find the words "program by x team" in a file it will print the fill path for the file.
 

ThinIce

Well-Known Member
Apr 27, 2006
352
9
168
Disillusioned in England
cPanel Access Level
Root Administrator
Take a look at man grep

I'd imagine you want something like grep -v "program by x team"

As:

-v, --invert-match Invert the sense of matching, to select non-matching lines
 

ThinIce

Well-Known Member
Apr 27, 2006
352
9
168
Disillusioned in England
cPanel Access Level
Root Administrator
The following is probably more appropriate then

-L, --files-without-match
Suppress normal output; instead print the name of each input
file from which no output would normally have been printed. The
scanning will stop on the first match.
 

InterServed

Well-Known Member
Jul 10, 2007
275
18
68
cPanel Access Level
DataCenter Provider
Hello,

How about this:
cd into the folder you mention having the .asp files.
Code:
du -ha | grep -i -o "\./.*asp" | xargs grep -i -n "$1" |grep -v "program by x team"
It should show only the files that doesn't contain your pattern and also ignore the files that does contain it. Warning ! This will show/output the content of all your .asp files that doesn't contain your pattern.
 
Last edited:

InterServed

Well-Known Member
Jul 10, 2007
275
18
68
cPanel Access Level
DataCenter Provider
Probably my wrong understanding on what your trying to accomplish.

If you wish the exclude the files that contain your pattern , and you still wish to grep them , that means there should be a second pattern or am i wrong ? You might need to provide a bit more accurate details , probably with some example-data so people could probably help you more.
 

whm-expert

Active Member
Nov 10, 2012
40
0
6
cPanel Access Level
DataCenter Provider
briefly, i need to do this:

list all ".asp" files that do not contain the words "program by x team".
if the file contain the word "program by x team" in any line of a specific file it will ignore it in results.

because the result list only the files that don't contain the words "program by x team"
 

InterServed

Well-Known Member
Jul 10, 2007
275
18
68
cPanel Access Level
DataCenter Provider
Did a small test with the command i provided you and for me it seems like it should do what you asked for:

Code:
-rw-r--r--   1 root root    6 May 19 14:30 1.asp
-rw-r--r--   1 root root    6 May 19 14:31 2.asp
-rw-r--r--   1 root root    6 May 19 14:31 3.asp
-rw-r--r--   1 root root   18 May 17 13:05 4.asp
On my testing , only file-name 4.asp contains your pattern:
Code:
1.asp -> 1asp-content
2.asp -> 2asp-content
3.asp -> 3asp-content
4.asp -> program by x team
Code:
[email protected] [~/asp-test]# du -ha | grep -i -o "\./.*asp" | xargs grep -i -n "$1" |grep -v "program by x team"
./3.asp:1:3asp-content
./1.asp:1:1asp-content
./2.asp:1:2asp-content
So as you can see , it only listed the files that doesn't contain your pattern "program by x team".
If you wish to search for something specific after ignoring the files that contains "program by x team" , then you could replace the "$1" from my command with your search pattern.
 
Last edited:

whm-expert

Active Member
Nov 10, 2012
40
0
6
cPanel Access Level
DataCenter Provider
hello
thank you for your answer
i try to execute your cmd and this is the output in ssh
Note: i replace .asp with .php
[email protected] [~]# du -ha | grep -i -o "\./.*php" | xargs grep -i -n "$1" |grep -v "program by x team"
output
grep: ./.cpanel/datastore/_usr_bin_php: No such file or directory

please can you tell me how can i search in a specific website like
/home/website/www/
 

whm-expert

Active Member
Nov 10, 2012
40
0
6
cPanel Access Level
DataCenter Provider
ok, i try this

du -ha | grep -i -o "\./.*php" | xargs grep -i -n "$1" |grep -v "program by x team"

it list all files in directory, please check the output, but all these files dont contain "program by x team"

output

Binary file ./en/function/news.php matches
Binary file ./en/function/topmenue.php matches
Binary file ./en/function/mysql.php matches
Binary file ./en/function/function.php matches
Binary file ./en/function/security.php matches
Binary file ./en/function/sources.php matches
[email protected] [/home/itech/www]#
 
Last edited:

InterServed

Well-Known Member
Jul 10, 2007
275
18
68
cPanel Access Level
DataCenter Provider
ok, i try this

du -ha | grep -i -o "\./.*php" | xargs grep -i -n "$1" |grep -v "program by x team"

it list all files in directory, please check the output, but all these files dont contain "program by x team"

output

Binary file ./en/function/news.php matches
Binary file ./en/function/topmenue.php matches
Binary file ./en/function/mysql.php matches
Binary file ./en/function/function.php matches
Binary file ./en/function/security.php matches
Binary file ./en/function/sources.php matches
[email protected] [/home/itech/www]#
Isn't that what you wanted ?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
it list all files in directory, please check the output, but all these files dont contain "program by x team"
As mentioned, the output of the command provided by InterServed appears to match your requirements. Is there another result you are seeking?

Thank you.