Using regular expression in filename
I have a script which gets as input a filename and does a grep on that. Now the problem is something like this:
The files I need to look in for the pattern are named as follows:
out, out.20050421.1234, out.20050421.2134, out.20050420.0012
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]!!!
"However, if I get the filename as out, doing a out[0-9]* doesnt work [I dont know why]"
Are you mising a period?
Shouldn't that be out.[0-9]*
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:
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.
Thanks for the suggestion. I shall certainly have a look into it.
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:
|All times are GMT -5. The time now is 03:43 PM.|