LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-25-2014, 11:08 AM   #1
postcd
Member
 
Registered: Oct 2013
Posts: 527

Rep: Reputation: Disabled
Find & grep - how to return pathes, not grep phrases ?


i used "grep -f my_phrasses.txt filename" as a part of linux Find command.
But the result is the phrasses not file names/file paths which is what i need..

i need to search millions of files and 20 phrasses in each of the file that match Find parameters...

this is end of my Find command:
-exec grep -f my_phrasses.txt {} \;

any idea how to return file pathes, not phrasses from my_phrasses.txt while maintaining low memory, cpu impact of the command? thx

Last edited by postcd; 11-25-2014 at 11:11 AM.
 
Old 11-25-2014, 11:48 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
change to
Code:
-exec grep -qf my_phrasses.txt {} \; -exec echo {} \;
 
Old 11-25-2014, 12:43 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Code:
-exec grep -l -f my_phrasses.txt {} +
This will pass the maximum allowed number of file paths to each grep invocation rather than invoking grep separately for each file. With the "-l" option, grep will print (just) the filename and proceed to the next file immediately when it finds a match, rather than continuing to search the rest of the current file.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] return value for find or grep for use as an if statement condition IneptCoder Linux - Newbie 3 07-19-2013 10:45 AM
[SOLVED] how to use cp find and grep together to copy a list of files using find with grep babhijit Linux - Newbie 10 07-03-2013 12:25 PM
need help .... find & grep mgra99 Linux - Newbie 2 12-31-2009 09:16 PM
grep for specific phrases Harry Seldon Linux - Newbie 5 05-27-2008 07:58 PM
How to check grep status when find elements return 0 ahjiefreak Programming 18 12-18-2007 05:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:44 PM.

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