LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-17-2010, 12:07 PM   #1
coolloo_djack
LQ Newbie
 
Registered: Feb 2010
Location: abidjan - côte d'ivoire
Distribution: redhat, debian, solaris
Posts: 7

Rep: Reputation: 0
Question How to match with a string containing litteral dot "." with grep command ?


Hiya!

I want to find out into some directory, all the files which names are composed of : A specific word README, a litteral "." and any string

file name sample like: "README.string"

thank you!
 
Old 03-17-2010, 12:16 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Don't use grep use ls
ls -l README.*
or find
find README.* /

will search the whole computer.
find README.* /home will only search home directories

or
ls -Rl | grep README.

will search from the current directory down through all subdirectories.

Or of course
find /home -name "README.*" will search home

Last edited by smoker; 03-17-2010 at 12:31 PM.
 
1 members found this post helpful.
Old 03-17-2010, 12:20 PM   #3
primerib
Member
 
Registered: Mar 2010
Posts: 48

Rep: Reputation: 20
It needs to be backslashed.

grep "." matches any char, grep "\." matches "." the period.

edit: sorry, misread your post. Do as Smoker suggested.
 
1 members found this post helpful.
Old 03-17-2010, 12:27 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Indeed, since . (dot) in a regular expression means any single character, you have to escape it using \ (backslash) or enclose it in a character list (square brackets) and use extended regexp (option -E)
Code:
$ ls | grep -E 'README\..+'
$ ls | grep -E 'README[.].+'
Anyway to just list certain filenames, you can use ls and the globbing capability of the shell:
Code:
$ ls README.*
this will be expanded to the filenames beginning with "README." and optionally followed by any suffix. In this case the dot is interpreted literally, since ls does not accept regular expressions as argument.
Finally, if you want to find files recursively in all sub-directories you can try the find command, as in:
Code:
$ find . -name 'README.*'
$ find . -regex '.*README\..+'
 
1 members found this post helpful.
Old 03-17-2010, 01:15 PM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Even better: 'echo *.*', since ls/find won't return names with spaces correctly.
 
1 members found this post helpful.
Old 03-17-2010, 10:07 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
bash 4

Code:
shopt -s globstar
for file in /path/**/*README.*
do
  echo $file
done
 
  


Reply

Tags
bash



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
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
[SOLVED] sed - Rule: "leftmost match, longest possible string, zero also matches."? quanta Programming 5 10-18-2009 08:37 AM
pattern match anything before "dot" ufmale Linux - Newbie 2 01-15-2009 12:35 PM
Regular expression matching , match "error string" but not "other error" jmcmillan Programming 3 07-07-2008 09:50 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:10 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
Open Source Consulting | Domain Registration