Solved

basic regular expressions

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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…
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now