LinuxQuestions.org
Review your favorite Linux distribution.
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 08-13-2009, 01:09 AM   #1
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Rep: Reputation: 30
about grep


I would like to grep the word "ABC" from a directory , if I use "grep ABC *" , it will output all word that contains ABC ( eg. ABCD , ABCDE.... ) , can advise if I only want to find the file have the word ABC , what can I do ? thx
 
Old 08-13-2009, 01:31 AM   #2
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 365
Blog Entries: 1

Rep: Reputation: 44
It's difficult to understand what you are asking for.

If you are looking to find all files in the current directory, or subdirectories thereof, which contain the pattern ABC anywhere in their name, then you want:

Code:
find . -name '*ABC*'
If, on the other hand, you want files that begin with the pattern ABC, then you do:

Code:
find . -name 'ABC*'
See man find for more info.

--jrtayloriv

Last edited by jrtayloriv; 08-13-2009 at 01:36 AM.
 
Old 08-13-2009, 01:32 AM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
grep " ABC " *
?
 
Old 08-13-2009, 01:46 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,695

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
Code:
ls *ABC*
?
 
Old 08-13-2009, 01:54 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,855

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
\b for word boundary:
grep '\bABC\b' *
 
Old 08-13-2009, 01:59 AM   #6
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 365
Blog Entries: 1

Rep: Reputation: 44
Quote:
Originally Posted by jlliagre View Post
Code:
ls *ABC*
?
I don't think that's what the OP is looking for -- that would list all of the files in any directory that contains the pattern ABC in its (i.e. the directory's) name.

--jrtayloriv

Last edited by jrtayloriv; 08-13-2009 at 02:00 AM. Reason: gender and whatnot ...
 
Old 08-13-2009, 01:59 AM   #7
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
if your ABC is having spaces around then try this...

grep " ABC " input > output

or

grep "ABC " input > output

or

grep -E " ABC |ABC " input > output
 
Old 08-13-2009, 02:06 AM   #8
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Original Poster
Rep: Reputation: 30
it seems not work,

my requirement is not difficult

in my directory , there are some files contains ABC , ABCD , ABCDE , what I want is to use grep to find the file that contains ABC , I use grep "ABC" * , it will show all the files ( includes ABCD , ABCDE ) , can advise what can i do ? thx
 
Old 08-13-2009, 02:32 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,695

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
Quote:
Originally Posted by jrtayloriv View Post
I don't think that's what the OP is looking for -- that would list all of the files in any directory that contains the pattern ABC in its (i.e. the directory's) name.
Indeed. You are right.
Quote:
Originally Posted by elainelaw
in my directory , there are some files contains ABC , ABCD , ABCDE , what I want is to use grep to find the file that contains ABC , I use grep "ABC" * , it will show all the files ( includes ABCD , ABCDE ) , can advise what can i do ? thx
ABCD and ABCD contains ABC. You should clarify your requirements.

Perhaps what you are looking for is:
Code:
ls | grep -w ABC
 
Old 08-13-2009, 04:25 AM   #10
geekfreaking
LQ Newbie
 
Registered: Jul 2009
Distribution: Arch
Posts: 4

Rep: Reputation: 0
Another way is:
Code:
find . -name ABC
which will find all files in the current directory and subdirectories with the name ABC and only the name ABC.
 
Old 08-13-2009, 04:47 AM   #11
nowonmai
Member
 
Registered: Jun 2003
Posts: 481

Rep: Reputation: 48
Are you looking for files that contain ABC or filenames that contain ABC?
 
  


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
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 07:12 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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