The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help in using awk and grep jisha Shell Programming and Scripting 6 04-09-2008 11:28 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-04-2007 11:59 PM
grep help ravi raj kumar UNIX for Dummies Questions & Answers 3 12-13-2006 11:41 PM
Grep pankajkrmishra Shell Programming and Scripting 15 08-31-2006 11:00 PM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-24-2006 09:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-17-2008
Registered User
 

Join Date: Apr 2007
Posts: 9
ls -l | grep *_D_CARM

Hello,

I'm trying to use the above command to produce a list of files ending in _D_CARM. However, when I execute the above it doesn't return anything. If I try ls -l *_D_CARM it shows the contents of every directory ending in _D_CARM .

Any suggestions?!

Cheers,

JW.
Reply With Quote
Forum Sponsor
  #2  
Old 04-17-2008
Registered User
 

Join Date: Apr 2008
Location: Frankfurt a.M.
Posts: 38
find . -type f -name "*_D_CARM"
Reply With Quote
  #3  
Old 04-17-2008
Registered User
 

Join Date: Apr 2007
Posts: 9
Thanks - actually meant to say I was looking for directories so just changed f to d.

Cheers!

JW
Reply With Quote
  #4  
Old 04-17-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Your original command was fine, but you can't use "*" in that sense in grep. Grep uses "regular expressions" which have a different syntax than your shell's wildcards.

grep matches the requested string anywhere on a line, so just take out the *.

To say "anything at all" in regular expressions, that's dot (.) followed by asterisk (*). Dot matches one character, any character, and asterisk means repeat the previous character (or character class, or whatever) zero or more times.

To restrict to just directories, you can do

Code:
ls -l */ | grep _D_CARM
Reply With Quote
  #5  
Old 04-17-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,931
You can use the shell for filename expansion:

Code:
ls -ld *D_CARM/
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0