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
Problem with GREP. syndex Shell Programming and Scripting 2 07-11-2007 10:44 AM
Grep Problem avadhani UNIX for Dummies Questions & Answers 8 06-23-2005 11:58 AM
grep problem asal_email2 UNIX for Dummies Questions & Answers 4 06-22-2005 05:49 PM
Grep Problem lesstjm Shell Programming and Scripting 2 10-27-2004 07:13 AM
Grep problem odogbolu98 Shell Programming and Scripting 3 02-18-2003 11:53 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-05-2004
Registered User
 

Join Date: Sep 2004
Posts: 78
grep problem

just a file with thousands of filenames and I wanna get all files with the same extension, like .Z

for example....
users/123/a.Z
users/424234/fafa.Z
users/424234/asda.log
daa/dsss/222/efesa-01002-01:00-A.Z

how to solve this issue?

when you make..

grep .Z file >newfile
grep ".Z" file >newfile
grep '.Z' file >newfile

..it finds only all files with a 'Z' in its filename.

also grep -x (exact) isn't the correct solution, because 0 files.

thx for any advice....
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-05-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
grep "\.Z$" file > newfile

This indicates to match .Z followed by the end of the line.

Cheers
ZB
Reply With Quote
  #3 (permalink)  
Old 11-05-2004
Registered User
 

Join Date: Sep 2004
Posts: 78
thx, working perfect....

^ - beginning
\ - ending of the line ?

what about the $ ?
Reply With Quote
  #4 (permalink)  
Old 11-05-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
^ - beginning of line
$ - end of line
\. - backslash escaped "." - to stop it being interpreted as a metacharacter - i.e. a literal full-stop.

Cheers
ZB
Reply With Quote
  #5 (permalink)  
Old 11-05-2004
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,434
\ is to escape the dot (.). In regular expression, a dot matches any single character. Escaping it means to treat the metacharacter (i.e. the dot in this case) literally.

$ matches the end-of-line. So, if you don't want to match something like .Za .ZIP etc. don't forget to have the $ in.
Reply With Quote
  #6 (permalink)  
Old 11-08-2004
Registered User
 

Join Date: Sep 2004
Posts: 78
thx..
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:33 PM.


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 Global Fact Book

Content Relevant URLs by vBSEO 3.2.0