- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- check string feature
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
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
01-10-2006 02:07 AM
01-10-2006 02:07 AM
I need to check that a variable read by a posix shell script is as follows
length 8,
first 5 digits are alfanumeric
last 3 digits are numeric
any help apprciated.
Thanks
Angelo
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2006 02:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2006 02:21 AM
01-10-2006 02:21 AM
Re: check string feature
When can leverage the enhanced grep command to match an anchored string.
checkvar()
{
typeset -i GSTAT=2
if [[ ${#} -eq 1 ]]
then
typeset X=${1}
shift
echo "${X}" | grep -E -q -e '^[A-Za-z0-9]{5}[0-9]{3}$'
GSTAT=${?}
fi
return ${GSTAT}
} # checkvar
read MYVAR
checkvar ${MYVAR}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Ok"
else
echo "Bad format"
fi
Man grep for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2006 02:57 AM
01-10-2006 02:57 AM
Re: check string feature
Similar in perl:
perl -e 'exit (@ARGV[0] =~ /^[A-Za-z0-9]{5}\d{3}$/)' $your_variable
This sets $? to 1 on match, 0 else.
Are you sure you mean Alphanumeric in those first 5, or perhaps just Alpha
Alpha: [A-Za-z]
AlphaNumeric: [A-Za-z0-9]
And if alpha-numeric, with "_" is allowed then you can use \w in perl:
perl -e 'exit (@ARGV[0] =~ /^\w{5}\d{3}$/)' $your_variable
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2006 03:03 AM
01-10-2006 03:03 AM