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 02-20-2014, 02:16 AM   #1
peacepanda
LQ Newbie
 
Registered: Oct 2012
Posts: 27

Rep: Reputation: Disabled
Grep pattern help!!!


I need to grep for a pattern in a directory say ABC.It give me some results like

./thisisgreat
./thisisfun
./thisiscool

Now I want the grep to exclude the ./thisisfun file is there a way I can do this?
 
Old 02-20-2014, 02:19 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Well firstly you would need to show how you grepped those results as grep does not work on files / directories?

Second, have a look at the man page and the -v option.
 
Old 02-20-2014, 02:24 AM   #3
peacepanda
LQ Newbie
 
Registered: Oct 2012
Posts: 27

Original Poster
Rep: Reputation: Disabled
Hi Grail,
I ran the command grep -irs "Pattern" . in the directory where I want the pattern to be searched.

peacepanda
 
Old 02-20-2014, 02:50 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
As grail suggested, use -v option with grep. Also, refer manual page of grep command for in-depth knowledge of the command and its option. For example:
Code:
user@sstem~$ ls -la | grep -v 'pattern_to_exclude'
user@sstem~$ ls -la | grep -v 'thisisfun'
Check this out: http://linux.die.net/man/1/grep
 
Old 02-20-2014, 04:30 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Well your grep must work a little differently, because when I type grep -irs "Pattern", my whole screen fills with all the matches from within all files within the directory.
 
  


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
[SOLVED] grep two pattern from a file Sattee Linux - General 18 06-13-2012 05:13 AM
[SOLVED] grep with pattern danielbmartin Linux - Newbie 3 12-05-2011 11:16 PM
grep till second pattern rattlesnakejoe Programming 1 11-22-2009 09:09 AM
grep exact pattern kapila Linux - Newbie 11 08-06-2009 03:58 AM
using grep when the pattern contains a ! farmerjoe Programming 9 03-16-2005 12:04 AM


All times are GMT -5. The time now is 04:44 AM.

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