LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-05-2012, 04:49 AM   #1
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Rep: Reputation: 30
grep files


Hello

I need to search in a folder /usr/local/app/data/
all files names which
have the word "house" inside the file
AND and which
does NOT have the word "car" inside the file.

Is it possible to do that with a single command (possibly using egrep , not sure if also sed could help) ?


Thank you

Last edited by graziano1968; 11-05-2012 at 05:17 AM.
 
Old 11-05-2012, 04:55 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If you mean the word "house" or "car" in the file name (not inside the files) you can try the find command:
Code:
find /usr/local/app/data -name \*house\* ! -name \*car\*
 
Old 11-05-2012, 05:05 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
ls /usr/local/app/data | sed -n '/house/{/car/!p}'
I don't think you can do it with a single GREP command
 
Old 11-05-2012, 05:08 AM   #4
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by colucix View Post
If you mean the word "house" or "car" in the file name (not inside the files) you can try the find command:
Code:
find /usr/local/app/data -name \*house\* ! -name \*car\*
No I mean text inside the file , not text inside the file name.
 
Old 11-05-2012, 05:20 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
I've seen some mighty contortions trying to use the wrong tool - usually because of some inane requirement. Teachers seem to be enamoured of such.

Use awk or perl.
 
Old 11-05-2012, 05:30 AM   #6
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by syg00 View Post
I've seen some mighty contortions trying to use the wrong tool - usually because of some inane requirement. Teachers seem to be enamoured of such.

Use awk or perl.
I could do this using php , however I was asking if there is an easy/fast way to do that using a single command line , as it seems no.
 
Old 11-05-2012, 05:45 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Not a single command, but a simple command line:
Code:
grep -lr house /usr/local/app/data/* | xargs grep -L car
 
Old 11-05-2012, 06:06 AM   #8
graziano1968
Member
 
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by colucix View Post
Not a single command, but a simple command line:
Code:
grep -lr house /usr/local/app/data/* | xargs grep -L car

Thank you
 
  


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
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
How to exclusive files by grep? thomas2004ch Linux - Software 6 03-20-2012 08:17 AM
'all files' switch for grep? maf9222 Linux - Newbie 2 06-14-2010 07:30 AM
Searching in files: How do I grep better? Elomis Linux - General 5 12-19-2007 01:52 AM
How to filter files in files and files which are in a sub-directory with "grep"? Piero Linux - Newbie 9 08-29-2003 02:38 AM

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

All times are GMT -5. The time now is 10:54 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