- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- filename pattern matching
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2003 02:55 AM
08-02-2003 02:55 AM
filename pattern matching
I need to write a script that will do pattern matching of filenames. The pattern to be matched is the first 3 characters of the file and they must have this pattern:
A=alpha N=numeric
ANN AAN ANA
Any help appreciated!
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2003 06:52 AM
08-02-2003 06:52 AM
Re: filename pattern matching
#!/usr/dt/bin/dtksh
while read filename
do
case $filename in
[:alpha:][:alnum:][:alnum:]*) print $filename;;
esac
done
of
if [[ "$filename" = [[:alpha:][:alnum:][:alnum:]]* ]] ;then
print $filename
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2003 06:52 AM
08-02-2003 06:52 AM
Re: filename pattern matching
I'll use regular expressions with 'awk' and 'ls' to generate the input:
# ls -l|awk '$NF~/^[[:alpha:]][0-9]][0-9]/ || $NF~/^[[:alpha:]][[:alpha:]][0-9]/ || $NF~/^[[:alpha:]][0-9]][[:alpha:]]/ {print $NF}'
This takes the output from 'ls' and examines the filename (the last field of each line) and prints it if it meets the criteria you specified for the first three characters. The '||' is an 'or' operator.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2003 06:56 AM
08-02-2003 06:56 AM
Re: filename pattern matching
ls |
sed -n '/^[:alpha:][:alpha:,0-9]\{2\}/p'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2003 11:07 AM
08-04-2003 11:07 AM
Re: filename pattern matching
I haven't tested it, but this should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2003 03:35 AM
08-05-2003 03:35 AM
Re: filename pattern matching
I have tested this and it seems to work:
(should be on a single line with no spaces between ??? and ???):
# ls
It has the obvious advantage of being easy to read!
The output from ls is redirected to egrep, which tries to match the extended reg. expression described between ??? and ???
The expression itself holds three alternatives, separated from one another by a pipe character.
Each alternative starts with the hat/caret character, which means ???must start with this???.
The allowed character combination for each alternative is described by so-called character-classes, e.g. [:alpha:] meaning any alphabetical character. A class is always surrounded by colons and a set of square brackets.
What you put in between square brackets, in this case the ???outer??? square brackets, means ???match any single one of the character(s) mentioned.
Hence, match any one alphabethical character appearing at the beginning looks like this: ^[[:alpha:]]
regards,
John K