?
Solved

basic regular expressions

Posted on 2011-03-06
4
Medium Priority
?
438 Views
Last Modified: 2012-06-27
Hi

Take these commands:

To find all the files on the system that have the text `audio' anywhere in their name, type:
$ locate audio [RET]

To find all the files on the system whose file names end with the text `ogg', type:
$ locate *ogg [RET]

Why doesn't *ogg find files with 'ogg' anywhere in the middle of the name? Why does adding the wildcard before ogg mean you are looking for ogg at the end of the name. I would have expected the first command to be *audio*

thanks
0
Comment
Question by:andieje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:nickswanjan
ID: 35046543
If your search pattern is a plain string (no wildcards) then locate displays all file names in the slocate database that contain that string. If your search pattern contains wildcards, then locate only displays file names that match the pattern exactly.

You can search using a regular expression by specifying the -i option.

You can use the 'man locate' to show the locate command options on your system.

See the following links for more details:

http://www.linfo.org/locate.html

http://www.softpanorama.org/Tools/locate.shtml
0
 
LVL 84

Expert Comment

by:ozo
ID: 35047005
locate "*ogg"
would pass the * to the locate program rather than expanding the file glob on the command line before calling locate
0
 
LVL 6

Accepted Solution

by:
t-max earned 200 total points
ID: 35063270
That's not really a regular expression per se, but only a pattern.
As suggested above, here's a quote at "man locate" to check how it works:
     Shell globbing and quoting characters (``*'', ``?'', ``\'', ``['' and
     ``]'') may be used in pattern, although they will have to be escaped from
     the shell.  Preceding any character with a backslash (``\'') eliminates
     any special meaning which it may have.  The matching differs in that no
     characters must be matched explicitly, including slashes (``/'').

     As a special case, a pattern containing no globbing characters (``foo'')
     is matched as though it were ``*foo*''.
0
 

Author Closing Comment

by:andieje
ID: 35072064
thanks - i hadn't appreciated the difference between reg ex and patterns
0

Featured Post

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question