Return
|
You want to interactively select groups of files to be processed based on file naming conventions.
Use the shell's File Name Substitution characters, which are similar to those used in DCL.
The 'wildcard' pattern matching characters in Unix are very similar to those used in VMS, but there are distinct and sometimes subtle differences. This can be a problem because you many not match the files you intended or match other files that you did not want to include.
First, you need to be aware of some important differences between VMS filenaming and Unix:
Unlike VMS any character can be used in a filename.
This includes characters that are special to the shell, like
the asterisk (* and even the carriage return, tab,
or line feed characters! The manual page for the Bourne Shell
advises that the characters *, ?,
[, or ] not be used in file or
directory names, but the operating system does nothing to
inforce these guidelines, so such files can be created
accidentally or intentially.
The period (.) is a special character in
filenames only if it is the first character. Unlike VMS,
the file extension in the filename:
myprog.f
is not a separate and distinct field in the file's name.
The period is just another character. Thus in Unix filenames
like:
this.is.my.kewl.file
are perfectly legal.When the first character of a filename is a period, it indicates to the shell that this is a 'hidden' file. By default such files will not shown in directory listings, nor matched by wildcard patterns unless the leading period is explicitly specified.
With these differences in mind, consider the following pattern matching characters:
| DCL | sh | Action |
|---|---|---|
* |
* |
Match any string, including the null string. |
% |
? |
Matches any one character. |
|
[...] |
Matches any one of the characters enclosed in brackets. The
hyphen may be used to indicate ranges of characters such as
[0-9] for any digit and [a-z] for
any lowercase letter. |
|
[!...] |
Match any character other than those that follow the exclamation point within the brackets. |
Do not confuse the shell's special pattern matching characters
with 'regular expression' pattern matching in programs like
grep, sed, and perl.
For example, in a regular expression, * matches
zero or more of the preceeding character. It does
not by itself match characters the way as it would when used
in a shell expression.
Again, because the period is not a special character (except
when it is first) it will be matched by the ? and
* wildcards. Given the following existing
filenames in the current directory:
.foo-bar
foo-bar
foo.bar
foo.foo
foosbar
very.foo.bar
consider the following example:
unix> ls foo?bar foo-bar foo.bar foosbar unix> ls foo* foo-bar foo.bar foo.foo foosbar unix> ls *foo* foo-bar foo.bar foo.foo foosbar very.foo.bar unix> ls .*foo* .foo-bar unix>
Here is an example of using the [...]
pattern matching construct:
unix> ls file.~[0-9]~ file.~1~ file.~3~ file.~5~ file.~7~ file.~9~ file.~2~ file.~4~ file.~6~ file.~8~ unix> ls file.~[0-9][0-9]~ file.~10~ unix> ls file.~[0-9]*~ file.~101~ file.~1~ file.~3~ file.~5~ file.~7~ file.~9~ file.~10~ file.~2~ file.~4~ file.~6~ file.~8~ unix>
As an exercise for the reader consider the following given the files:
myfile
myfile.1
myfile.2
myfile.x
why does the last command in the following example not
match the file myfile?
unix> ls myfile* myfile myfile.1 myfile.2 myfile.x unix> ls myfile*[!x] myfile.1 myfile.2 unix>
One last important note -- always remember that it is the
shell that expands the wildcard characters before
starting up the program. Use the echo command
to easily illustrate this.
unix> echo myfile* myfile myfile.1 myfile.2 myfile.x unix>
unix> echo no*such*file no*such*file unix>
2.4 - Finding Files;
Chapter 2 of Unix for OpenVMS Users
;
Chapter 1 of Unix Power Tools
.
  Return
|
|
Colophon: |
|
||||
|
This page maintained by: Bill.Costa@unh.edu of the Enterprise Computing Group in the dept of Computing & Information Sevices at the University of New Hampshire |
|
||||