The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Counting files in a directory that match a pattern dsravan Shell Programming and Scripting 31 07-24-2006 12:12 PM
search all files for a pattern ynaik002 UNIX for Dummies Questions & Answers 4 02-23-2006 03:51 PM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM
List files that do not match the search pattern olapxpert UNIX for Dummies Questions & Answers 7 04-14-2005 04:49 PM
List files that do not match the search pattern olapxpert IP Networking 1 04-14-2005 03:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-16-2008
madankumar madankumar is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore
Posts: 8
search files which doesnot match pattern ?

Hi

I need a command to search files in a directory which does not match with pattern .. Plz send me this

Ex : Test is directory and has some 10 files with different name all are with *.dat extension , need to search files which doesnot contain word "Dummy file".


Thanks
  #2 (permalink)  
Old 07-16-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by madankumar View Post
Hi

I need a command to search files in a directory which does not match with pattern .. Plz send me this

Ex : Test is directory and has some 10 files with different name all are with *.dat extension , need to search files which doesnot contain word "Dummy file".


Thanks
Code:
find . -name "*.dat" | xargs grep -v "Dummy file"
Thanks
  #3 (permalink)  
Old 07-16-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
That will just display all lines in all files that do not contain "Dummy file".

Try this instead:

Code:
# list files that *do* contain "Dummy file" and save in a file
grep -l "Dummy file" * > /tmp/matches
# use that file to exclude them from the list of files
ls | grep -xvf /tmp/matches
  #4 (permalink)  
Old 05-18-2009
balpreetspankaj balpreetspankaj is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
Use this

find -name "*.dat" | xargs grep -L "Dummy File"
  #5 (permalink)  
Old 05-18-2009
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Why reply to a thread that is 10 months old, which has already been answered, and give the wrong answer???
  #6 (permalink)  
Old 05-18-2009
balpreetspankaj balpreetspankaj is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
Oh ... I just came across this using Google looking for something. Thought I would post the answer. Maybe, someone else would benefit. Anyways, I dont see why the answer is wrong.
  #7 (permalink)  
Old 05-18-2009
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
My apologies, I replied in haste... your answer is correct. I misread -L as -l (I didn't know about the -L inverse feature in GNU grep).
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0