Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-20-2014, 05:13 AM   #1
Registered: Oct 2013
Posts: 443

Rep: Reputation: Disabled
Bash: Find command to search multiple phrasses in each file?

declare -a phrasses
phrasses[0]="phrasse 1"
phrasses[1]="phrasse 2 something'something\"something\"');"
phrasses[2]="phrasse 3"


for (( i=0;i<${#phrasses[*]};i++ )); do
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
Old 06-20-2014, 05:38 AM   #2
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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:
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.
Old 06-21-2014, 02:23 PM   #3
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
And grep allows for alternatives... "phrase | phrase2 | phrase3"
Old 08-30-2014, 11:18 AM   #4
Registered: Oct 2013
Posts: 443

Original Poster
Rep: Reputation: Disabled

Thank You,

so this is part of my find command:

-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;?>



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how we can find and replace multiple file using sed command jayakumar01 Linux - Server 1 04-05-2012 08:53 AM
Find and replace a string in a file using perl command from bash script koundinya749 Programming 5 02-15-2011 05:52 PM
find command to search file modified b-RAM Linux - General 3 05-27-2009 12:39 AM
giving search-string(s) from a file to linux "find" command Fond_of_Opensource Linux - Newbie 3 02-02-2009 07:14 PM
Find command - multiple file types mrclisdue Linux - General 4 07-03-2006 04:48 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:05 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration