LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash: Find command to search multiple phrasses in each file? (https://www.linuxquestions.org/questions/linux-newbie-8/bash-find-command-to-search-multiple-phrasses-in-each-file-4175508599/)

postcd 06-20-2014 04:13 AM

Bash: Find command to search multiple phrasses in each file?
 
Quote:

declare -a phrasses
phrasses[0]="phrasse 1"
phrasses[1]="phrasse 2 something'something\"something\" https://www.domain.com/');"
phrasses[2]="phrasse 3"

wheretosearch=/home
outputfile=/tmp/find_malicious_output.txt

for (( i=0;i<${#phrasses[*]};i++ )); do
phrasse=${phrasses[$i]}
echo "$phrasse"
find $wheretosearch -type f -size -800k -mmin -1440 -exec grep -l "$phrasse" {} \; >> $outputfile
Please how can i make this to search one file only once and all phrasses in it?
I mean i have around 30 phrasses and i dont want to do search 30 times, but only 1 time and search in file, you know to save io resources and time

shivaa 06-20-2014 04:38 AM

So where are you stuck ? Also, make it clear, do you want to search some particular files or want to serach some keyword in the file content?
You can use -name option, instead of grep piped with find cmd, like:
Code:

find $wheretosearch -type f -size -800k -mmin -1440 -name "$phrasse" -print >> $outputfile
Don't forget to close for loop in your script with do-done.

jpollard 06-21-2014 01:23 PM

And grep allows for alternatives... "phrase | phrase2 | phrase3"

postcd 08-30-2014 10:18 AM

Thank You,

so this is part of my find command:

Quote:

-exec grep -l "$phrasse" {} \; >> $outputfile
how i can make it so i can search for not one, but twenty phrasses and if any or several of them found in the file, it output into the file?

the search phrasses will contain example this:

url=<?php echo $rand_url;?>
http://www
\"ftp\"
\'ftp\'

:-O


All times are GMT -5. The time now is 07:51 PM.