Solved

basic regular expressions

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP error function not working on AWS 10 163
Apache module 5 81
Exchange Server Send connector and DNS Round Robin ? 6 70
Bash script to include windows servers 13 34
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses

738 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