Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My program gets as input the filename upto before the last . [DOT], like either, out [for the first file] or out.20050421 for the second and third files.
Now, in the second case [file name input out.20050421], I directly can use grep pattern out.20050421.[0-9]* to get results from the second and third files stated above [desired output]
However, if I get the filename as out, doing a out[0-9]* doesnt work [I dont know why]
Can someone give me a solution to this[assuming that I have not confused people enough]!!!
Last edited by smart_sagittari; 04-22-2005 at 02:31 AM.
Thats the problem. The base file doesnt have a . [DOT]. How can I go abt this. Is there some way I can include a . inside the brackets [so as to consider it an optional dot]?
I'm not sure your wildcard is doing what you hope it does (assuming this is a shell script and not perl).
In the shell, using "[0-9]*" says there must be a single character between 0 and 9 (inclusive), followed by any number of other characters. In other words, "out[0-9]*" would match:
out0
out1
out2a
out3abc
out456z
...
It's not the same behavior as you'd get from a traditional regular expression.
You might want to consider using the '?' wildcard, but I don't know if that would really solve the problem.
If you're using Bash, you'll be interested to read the secion regarding "pathname expansion". Specifically, the pattern matching sub-section. It explains how the wildcards work. In addition to the basic wildcards (*, ?, [] ), there are some expressions that have similar effects as traditional regular expressions. For instance:
Code:
If the extglob shell option is enabled using the shopt builtin, several
extended pattern matching operators are recognized. In the following
description, a pattern-list is a list of one or more patterns separated
by a |. Composite patterns may be formed using one or more of the fol-
lowing sub-patterns:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches exactly one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
That's from my man page (bash version 3).
Last edited by Dark_Helmet; 04-25-2005 at 01:22 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.