LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-12-2012, 08:37 AM   #1
whossa
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Rep: Reputation: Disabled
grep a text in files and print the file name who don't contain such text


Hello all,

I'm going to grep a text in the files and wanna to just print the file names who don't contain this text, apparently, use
find . -name ***|xargs grep -lv pattern won't work, this will print all files.

Then I use
find . -name ***|tee ../all.txt|xargs grep -l pattern|tee ../contained.txt

then
diff ../all.txt ../contained.txt

It could work yet too stupid, do anyone have elegant solution? Much appreciated! I could use perl to filter out this two file list yet this may be unnecessary!

Last edited by whossa; 04-12-2012 at 08:40 AM. Reason: more precise
 
Old 04-12-2012, 09:03 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,869
Blog Entries: 14

Rep: Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111
grep -L

From the man page:
Quote:
-L, --files-without-match
Suppress normal output; instead print the name of each input
file from which no output would normally have been printed. The
scanning will stop on the first match.

For most UNIX/Linux commands there are manual (man pages). Typing "man <command>" will show it to you. Also on Linux some things also have info pages. Typing "info <command>" will show that to you. You can even type "man man" to find out how the man command works.
 
Old 04-12-2012, 09:05 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,345

Rep: Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747Reputation: 2747
grep -lc will print counts, and you can grep the zeros:
grep -lc pattern files | grep ':0$'

from the other hand in general instead of the chain of find, tee, xargs, grep and tee (and maybe sed, awk, and cat) you would better try a single perl script.
 
Old 04-12-2012, 09:22 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,869
Blog Entries: 14

Rep: Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111
UNIX/Linux is case sensitive. "-l" and "-L" have different meanings - in fact they do the exact opposite of each other.
 
Old 04-12-2012, 09:07 PM   #5
whossa
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks for MensaWater's help, that's great!
 
Old 04-13-2012, 07:49 AM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,869
Blog Entries: 14

Rep: Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111
Glad I could help.

Please go to thread tools and mark this as solved. It helps others with similar issues in future more quickly find threads with solutions.
 
  


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
Combine multiple text files into one text file? dirtydog7655 Linux - Newbie 6 05-16-2013 10:47 PM
how to print part of text of a text file in bold and color using shellscript swapna sree Linux - Newbie 25 07-12-2011 11:19 AM
[SOLVED] read a text file distrubute its contents on different text files magische_vogel Programming 13 02-26-2011 06:51 PM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
Steps needed to convert multiple text files into one master text file jamtech Programming 5 10-07-2007 11:24 PM


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