- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Check for format
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
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
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
02-12-2007 04:27 PM
02-12-2007 04:27 PM
i want to check whether the filename is like
XXXNN.XXNNNNNN.XXX
where X-> alphabets,
N-> numbers
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2007 05:22 PM - edited 10-19-2011 01:05 PM
02-12-2007 05:22 PM - edited 10-19-2011 01:05 PM
SolutionYou can use pattern matching:
[A-Za-z_][A-Za-z_][A-Za-z_][0-9][0-9].[A-Za-z_][A-Za-z_][0-9][0-9][0-9][0-9][0-9][0-9].[A-Za-z_][A-Za-z_][A-Za-z_]
for i in $*; do
echo $i | grep '[A-Za-z_][A-Za-z_][A-Za-z_][0-9][0-9]\.[A-Za-z_][A-Za-z_][0-9][0-9][0-9][0-9][0-9][0-9]\.[A-Za-z_][A-Za-z_][A-Za-z_]'
done
This will echo the name if it matches.
(The grep is one long pattern.)
Perhaps this is easier to understand:
A="[A-Za-z_]" # includes "_" if you want
N="[0-9]"
for i in $*; do
echo $i | grep "$A$A$A$N$N\.$A$A$N$N$N$N$N$N\.$A$A$A"
done
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2007 06:47 PM - edited 10-19-2011 01:06 PM
02-12-2007 06:47 PM - edited 10-19-2011 01:06 PM
Re: Check for format
Or you could use:
A="[[:alpha:]]" # no "_" this time
N="[[:digit:]]"
for i in $*; do
echo $i | grep "$A\{3\}$N\{2\}\.$A\{2\}$N\{6\}\.$A\{3\}"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2007 03:14 AM
02-13-2007 03:14 AM
Re: Check for format
You could do pass your file name to this Perl snippet to test it. If the name meets your criteria, "ok" is printed, otherwise nothing:
# echo abc12.de123456.fgh | perl -nle 'print "ok" if /^\pL{3}\d\d\.\pL\pL\d{6}\.\pL{3}$/'
The \pL represents one alphabetic character. The \d stands for one digit. The {n} notation specifies the number of occurances. The caret anchors the match to the beginning of the string, and the dollar-sign to the end.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2007 08:52 PM
02-13-2007 08:52 PM
Re: Check for format
ll [A-Za-z_][A-Za-z_][A-Za-z_][0-9][0-9].[A-Za-z_][A-Za-z_][0-9][0-9][0-9][0-9][0-9][0-9].[A-Za-z_][A-Za-z_][A-Za-z_]
HTH,
Art