LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-11-2011, 06:35 AM   #1
PatrickDickey
Member
 
Registered: Sep 2011
Location: Muscatine, IA
Distribution: Ubuntu variants (ubuntu/Mythbuntu) and Windows Home Server/Windows 7
Posts: 33

Rep: Reputation: Disabled
Question How to find files that contain one string, but don't contain another.


Here's my problem. I'm trying to create a v4l driver for my TV Tuner. Some of the files contain a line that starts with "kfree". If the file doesn't have an #include <linux/slab.h> line, then it won't compile properly.

I tried using
Code:
grep -lr "kfree" v4l-*/*
and it gave me well over 400 files (some that also have the #include line). So, essentially what I'm looking for is:

Find all files which contain "kfree" but don't contain "linux/slab.h" in the v4l-*directory (and it's subdirectories). And only list their path and filenames.

I should note that the v4l-* directory is actually v4l-dvb-80e-30c6512030ac which is why I'm shortening it up.

Any answers are greatly appreciated. I'm running Ubuntu 11.04 with Unity (so I can potentially use either command-line or graphical find programs).

Have a great week
Patrick.
 
Old 09-11-2011, 06:53 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
So something like:
Code:
grep -vl 'linux/slab.h' $(grep -lr "kfree" v4l-*/*)
 
Old 09-11-2011, 07:00 AM   #3
PatrickDickey
Member
 
Registered: Sep 2011
Location: Muscatine, IA
Distribution: Ubuntu variants (ubuntu/Mythbuntu) and Windows Home Server/Windows 7
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
So something like:
Code:
grep -vl 'linux/slab.h' $(grep -lr "kfree" v4l-*/*)
So, if I want to redirect the results to a text file named kfree2.txt, then it would be
Code:
 grep -vl 'linux/slab.h' $(grep -lr "kfree" v4l-*/*) >> kfree2.txt
correct?

Thanks for the quick answer. I'm still at 300+ files, so hopefully this will knock things down a bit.

I had to tweak the command a bit. The -vl wasn't working (it gave me the same files that I already had), so I put in this

Code:
grep -L 'linux/slab.h' $(grep -lr "kfree" v4l-*/*) >> kfree2.txt
and it knocked it down to 190 files. So, hopefully that is the right number. Thanks for the help though, since I wouldn't have even gotten close without you.

Have a great day
Patrick.

Last edited by PatrickDickey; 09-11-2011 at 07:12 AM. Reason: added in the code for the command that worked.
 
  


Reply


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
How to list all the files that don't contain pattern1 and append a new string ? magische_vogel Programming 10 03-25-2011 09:39 AM
[SOLVED] How to find a string in files under the current directory? thomas2004ch Linux - Newbie 4 10-05-2010 07:41 AM
[SOLVED] Find and delete string in text files damgar Linux - Software 3 03-06-2010 10:27 PM
find a string in all ASCII files of a system markraem Linux - Software 5 12-12-2007 05:08 AM
How to find those files having specific string??? saeed Red Hat 4 07-19-2006 12:50 PM


All times are GMT -5. The time now is 08:33 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration