LinuxQuestions.org
Review your favorite Linux distribution.
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 05-03-2007, 09:19 AM   #1
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Rep: Reputation: 0
list all files *not* containing pattern


I can list all lines in files not containing a pattern, and list all files that do, but how do I list all files that don't match a pattern?
 
Old 05-03-2007, 09:31 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Code:
ls | grep -v searchstring
edit: I might have misunderstood. Do you want to search the contents of the files or just the directory?

Last edited by pwc101; 05-03-2007 at 09:33 AM.
 
Old 05-03-2007, 09:36 AM   #3
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
With bash:

Code:
shopt -s extglob
ls -d !(*your_pattern*)
With ksh:

Code:
ls -d !(*your_pattern*)
 
Old 05-03-2007, 09:45 AM   #4
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
ls -d !MYPATTERN
...yields:
bash: !MYPATTERN: event not found

Quote:
Do you want to search the contents of the files or just the directory?
The contents of the files.
 
Old 05-03-2007, 09:47 AM   #5
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Tried radoulov's suggestion *with* parentheses, and no error although it seems to be searching file names, not contents.
 
Old 05-03-2007, 09:50 AM   #6
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Quote:
Originally Posted by code-breaker
...yields:
bash: !MYPATTERN: event not found
[...]
And did you issue
Code:
shopt -s extglob
as I said?

Quote:
[...]
The contents of the files.
[...]
The command I suggested matches filenames, not content.
 
Old 05-03-2007, 09:55 AM   #7
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
Quote:
Originally Posted by code-breaker
I can list all lines in files not containing a pattern, and list all files that do, but how do I list all files that don't match a pattern?
Misread your question. EDIT: See post below.

Last edited by radoulov; 05-03-2007 at 10:04 AM.
 
Old 05-03-2007, 10:04 AM   #8
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
OK,
may be you need this (assuming GNU grep):
Code:
grep -L "your_pattern" your_glob or filename(s)
 
Old 05-03-2007, 12:07 PM   #9
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks radoulov, I'll try it tonight when I get home.
 
  


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
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
How to recursively rename files using their directory name pattern ceg4048 Linux - General 2 09-28-2005 01:16 PM
What is the Package Search pattern Syntax for dpkg --list? Akhran Debian 3 08-23-2005 05:23 AM
list files NOT matching a pattern smart_sagittari Linux - Newbie 9 05-20-2005 05:32 AM
search for pattern in files and replace mizuki26 Linux - Newbie 3 01-04-2004 11:57 AM

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

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