Globbing slash Wildcarding Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Globbing slash Wildcarding Question
# 1  
Old 02-01-2007
Globbing slash Wildcarding Question

I am on HP-UX and I am trying to come up with a method to call in a list of files named like so.

filename020107.dat filename020207.dat filename020307.dat

Obviously I can list them ls them like so, ls filename*.dat. In case you did not notice the number is a date and I was hoping to match the filenames like so, ls filename[01-12][01-31][00-99].dat thus guaranteeing my date format. There could possibly be files named filenameabc123.dat or anything for that matter and I wanted to fine tune my listing a little more. I really though this form of globbing worked, but I have been unsuccessful.

filename[01-12][01-31][00-99].dat not found

Am I missing something or am I just wrong in thinking you can glob in this manner? Thanks in adavance.
# 2  
Old 02-01-2007
filename[01][0-9][0-3][0-9][0-9][0-9].dat
# 3  
Old 02-01-2007
Quote:
Originally Posted by sb008
filename[01][0-9][0-3][0-9][0-9][0-9].dat
That would allow for invalid dates, e.g., filename009900.dat. In ksh, give this a try (slightly tested):
Code:
filename@(0[1-9]|1[0-2])@(0[1-9]|[12][0-9]|3[0-1])@([0-9][0-9]).dat

Keep in mind that you still would be allowing for non-existent dates such as February 31 or November 31.
# 4  
Old 02-01-2007
Quote:
Originally Posted by Glenn Arndt
That would allow for invalid dates, e.g., filename009900.dat. In ksh, give this a try (slightly tested):
Code:
filename@(0[1-9]|1[0-2])@(0[1-9]|[12][0-9]|3[0-1])@([0-9][0-9]).dat

Keep in mind that you still would be allowing for non-existent dates such as February 31 or November 31.
Based on the fact that was stated that the format of the files is:
filename<date>.dat
the regular expression would be strict enough, since it's fair to assume that whatever program produces these output files produces them with a valid date in the file name.

If other files are around with a similar format, your regular expression, even though it's more strict, would be as useless as mine. Unless ofcourse you promote the filosophy that a statement is better if it has a smaller chance on producing errors.

The only valid option, if files with similar patterns are around, is to isolate the date part from the filename and use e.g. a date conversion command/tool on that pattern and test for the return code.
# 5  
Old 02-02-2007
MySQL

I don't disagree with anything you have said, however...
Quote:
Originally Posted by sb008
Based on the fact that was stated that the format of the files is:
filename<date>.dat
the regular expression would be strict enough, since it's fair to assume that whatever program produces these output files produces them with a valid date in the file name.
If you're going to assume that whatever program produces these output files produces them with a valid date in the file name, 1) you've made your regular expression unnecessarily strict; that is, you could have just as easily used filename[0-9][0-9][0-9][0-9][0-9][0-9].dat (although less reasonable, it's certainly easier to type), and 2) you're assuming the original poster's request is irrelevant, since his requirement was to "match the filenames like so, ls filename[01-12][01-31][00-99].dat thus guaranteeing [his] date format".
Quote:
Originally Posted by sb008
If other files are around with a similar format, your regular expression, even though it's more strict, would be as useless as mine. Unless ofcourse you promote the filosophy that a statement is better if it has a smaller chance on producing errors.
In most cases here on unix.com, I do promote that philosophy.
Quote:
Originally Posted by sb008
The only valid option, if files with similar patterns are around, is to isolate the date part from the filename and use e.g. a date conversion command/tool on that pattern and test for the return code.
I agree, and that is something I have considered. However, I don't know of one offhand, and although I could write one, unless you can suggest an existing one to me, I can not offer it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File globbing order

Hi , I'm facing a different behaviour with one of my shell script for last few days. It was working good before that. here is my code for the script FileRemove.sh #get the file name# file1=$1 file2=$2 rm $file1 # delete the old file mv $file2 <target path> #move the new file to the target... (5 Replies)
Discussion started by: poova
5 Replies

2. Shell Programming and Scripting

Negation in Bash Globbing

$ ls -1 a.1 b.1 x_a.1 x_b.1 $ ls -1 * b.1 x_a.1 x_b.1 $ ls -1 ** a.1 b.1 x_a.1 x_b.1The last result is not as expected. Why? Thanks. (2 Replies)
Discussion started by: carloszhang
2 Replies

3. Shell Programming and Scripting

Wildcarding in a Perl @ARGV Context?

Hello folks! While "sedding" about again, I ran into this little conundrum du jour:#!/usr/bin/perl use strict; use warnings; use diagnostics; @ARGV = ('./afile.dat', './*.txt'); $^I = ''; while (<>) { s/Twinkies/Dinner/g; print; }When run, perl complains,...but, of... (2 Replies)
Discussion started by: LinQ
2 Replies

4. Shell Programming and Scripting

Wildcarding in a Perl @ARGV Context?

Hello folks! While "sedding" about again, I ran into this little conundrum du jour:#!/usr/bin/perl use strict; use warnings; use diagnostics; @ARGV = ('./afile.dat', './*.txt'); $^I = ''; while (<>) { s/Twinkies/Dinner/g; print; }When run, perl complains,...but, of... (1 Reply)
Discussion started by: LinQ
1 Replies

5. UNIX for Dummies Questions & Answers

File globbing questions

hi guys, jus some file globbing questions sed "s/^.*on//" what does the full stop and asterisk means? i onli know that ^ means inverse or not (1 Reply)
Discussion started by: ment0smintz
1 Replies

6. Shell Programming and Scripting

Globbing or not globbing

Hi guys, Here is a simple script. It writes the current time to specific files in a directory. The arguments are the names of the files to write the date to (without path nor extension). root:~# cat /usr/local/bin/dummy.sh #!/bin/sh -e for file in $@; do date >> /var/lib/$file.dat... (11 Replies)
Discussion started by: chebarbudo
11 Replies

7. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

8. UNIX for Advanced & Expert Users

Substitute single backward-slash with the double backward-slash

Hi, I have a path like this c:\test\sample\programs, i need to change thiis to c:\\test\\sample\\programs. How to perform this? I tried tr command but it didn't help me. Thanks Vijayan (3 Replies)
Discussion started by: mvictorvijayan
3 Replies

9. Shell Programming and Scripting

globbing, $# is too high after wildcard expansion in bash script

How can I pass in an argument such as "*.k" to a bash script without having to double-quote *.k and not having *.k `glob` to match all files in the pattern? I tried using noglob in my script but this didn't work the way I thought it would.. expansion is still occuring, $# is higher than I... (3 Replies)
Discussion started by: zoo591
3 Replies

10. Shell Programming and Scripting

awk / bash globbing question

I would like to process a list of files matching: GPS*\.xyz with an awk script. I would then like to output the files to GPS*\.xyz.out (e.g. the same file name appended with .out). Something like: awk '{if(NR==1) {offset=-$1}; $1=$1+offset; print }' GPS*.xyz this does exactly what I want EXCEPT... (3 Replies)
Discussion started by: franzke
3 Replies
Login or Register to Ask a Question