- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Checking script parameter (Respecting a mask)
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
11-30-2016 02:38 AM - edited 11-30-2016 03:02 AM
11-30-2016 02:38 AM - edited 11-30-2016 03:02 AM
Hi,
my script accept only one parameter
./myscript.ksh param1
I need to write a routine to check and validate the parameter first priot to actions and this parameter needs to contain at least something matching NN_NN_NNNN_NN_NN_NN_NNNN format. Where N is digit between 0 and 9.
Example:
myscript.ksh serveurX120_11_2016_23_55_55_0200_commentZ21
myscript.ksh magic10020_11_2016_23_55_55_0200_commentZ23
Then, how to be sure that something matching NN_NN_NNNN_NN_NN_NN_NNNN is part of the parameter ?
Your help is very welcome, any idea here ?
Thanks in advance,
Den
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2016 04:58 AM
11-30-2016 04:58 AM
SolutionOne possible way, using "sed" [*]:
mba$ p1='[0-9][0-9]_[0-9][0-9]_[0-9][0-9][0-9][0-9]_' # Part 1.
mba$ p2='[0-9][0-9]_[0-9][0-9]_[0-9][0-9]_[0-9][0-9][0-9][0-9]' # Part 2.
mba$ g1='erveurX120_11_2016_23_55_55_0200_commentZ21' # Good string.
mba$ b1='erveurX120_11_2016_23_55_55_02o0_commentZ21' # Bad string.
mba$ echo "${g1}" | sed -e "s/..*\(${p1}${p2}\)..*/\1/"
20_11_2016_23_55_55_0200
mba$ echo "${b1}" | sed -e "s/..*\(${p1}${p2}\)..*/\1/"
erveurX120_11_2016_23_55_55_02o0_commentZ21
If this "sed" command returns the original string, then the
NN_NN_NNNN_NN_NN_NN_NNNN pattern was not matched.
The "..*" parts here require at least one non-pattern character
before and after the pattern. As usual in such situations, many things
are possible, and you must decide exactly what you wish to accept and
reject.
[*] As I always say, if you can't do it with "sed", then it doesn't
need doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2016 05:49 AM
11-30-2016 05:49 AM
Re: Checking script parameter (Respecting a mask)
Hi Steven,
Thank you very much, it works perfectly.
Kind regards,
Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2016 05:52 AM - edited 11-30-2016 06:12 AM
11-30-2016 05:52 AM - edited 11-30-2016 06:12 AM
Re: Checking script parameter (Respecting a mask)
Almost OK.
As you mention, it cannot work with:
aaaa10_10_2017_23_12_22_0004
10_10_2017_23_12_22_0004eeee
10_10_2017_23_12_22_0004
Alll these strings are respecting the mask.
I could add systematically Z before and Z after for my test. Correct ?
Kind regards, Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2016 10:15 AM
11-30-2016 10:15 AM
Re: Checking script parameter (Respecting a mask)
> The "..*" parts here require at least one non-pattern character
> before and after the pattern. [...]
> I could add systematically Z before and Z after for my test. Correct ?
Sure.
mba$ g2='aaaa10_10_2017_23_12_22_0004'
mba$ g3='10_10_2017_23_12_22_0004eeee'
mba$ g4='10_10_2017_23_12_22_0004'
mba$ echo "Z${g1}Z" | sed -e "s/..*\(${p1}${p2}\)..*/\1/"
20_11_2016_23_55_55_0200
mba$ echo "Z${g2}Z" | sed -e "s/..*\(${p1}${p2}\)..*/\1/"
10_10_2017_23_12_22_0004
mba$ echo "Z${g3}Z" | sed -e "s/..*\(${p1}${p2}\)..*/\1/"
10_10_2017_23_12_22_0004
mba$ echo "Z${g4}Z" | sed -e "s/..*\(${p1}${p2}\)..*/\1/"
10_10_2017_23_12_22_0004
mba$ echo "Z${b1}Z" | sed -e "s/..*\(${p1}${p2}\)..*/\1/"
ZerveurX120_11_2016_23_55_55_02o0_commentZ21Z
That way, the result from every bad string, and no good string, will
begin (and end) with "Z".