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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-12-2012, 08:37 AM
|
#1
|
LQ Newbie
Registered: Nov 2011
Posts: 6
Rep: 
|
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
|
|
|
04-12-2012, 09:03 AM
|
#2
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
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.
|
|
|
04-12-2012, 09:05 AM
|
#3
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,988
|
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.
|
|
|
04-12-2012, 09:22 AM
|
#4
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
UNIX/Linux is case sensitive. "-l" and "-L" have different meanings - in fact they do the exact opposite of each other.
|
|
|
04-12-2012, 09:07 PM
|
#5
|
LQ Newbie
Registered: Nov 2011
Posts: 6
Original Poster
Rep: 
|
Thanks for MensaWater's help, that's great!
|
|
|
04-13-2012, 07:49 AM
|
#6
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
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.
|
|
|
All times are GMT -5. The time now is 06:01 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|