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
Solved

basic regular expressions

Posted on 2011-03-06
4
407 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
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 50 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

829 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