- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: perl - substitution
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
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
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
тАО07-08-2003 01:54 PM
тАО07-08-2003 01:54 PM
i am writing a perl script. and this does something like below.
$_=@tmporaCommand[$size-1];
#$_ contains something like `ora_pmon_(A1|A2|A3)` or 'ora_pmon_A1'
s/'ora_pmon_\(//;
s/\(//;
s/\)//;
s/'//;
@oraInstance = split(/\|/);
#want the array elements to be like A1, A2, A3
but there should be something like
sed -e 's/'ora_pmon_\(//' -e 's/\(//;' ...
here as well! right?
any pointer?
-balaji
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2003 06:12 AM
тАО07-09-2003 06:12 AM
Re: perl - substitution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2003 06:42 AM
тАО07-09-2003 06:42 AM
Re: perl - substitution
In fact perl supports a -e command line option through which you can avoid writing a multi line program, although at the cost of readability, probably...
try this -
perl -h
Just learning perl.. so can't give any examples... avlovu nalla theriyaadu...
HTH.
- ramd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2003 08:01 AM
тАО07-09-2003 08:01 AM
Re: perl - substitution
this a big program and what is shown above is snippet of the code.
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2003 09:33 AM
тАО07-09-2003 09:33 AM
Solutions/ora_pmon_[(]?([^)]*)[)]?/\1/
The square brackets and ? indicate an optional pattern (the parens). Putting parens around a pattern allows you to reference it later as \1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2003 10:19 AM
тАО07-09-2003 10:19 AM
Re: perl - substitution
if possible can u explain this better or point me to a resource.
tia
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-10-2003 08:14 AM
тАО07-10-2003 08:14 AM
Re: perl - substitution
What you want to take a close look at is regular expressions (regexps). Very powerful. Once you start playing with them, they will make your life easier. Just watch out for "greedy" behavior - by default, a pattern will match as much text as possible.
Let's look at the pattern I suggested:
s/ora_pmon_[(]?([^)]*)[)]?/\1/
The basic structure is
s/patternToMatch/replacementText/flags
We'll ignore flags, since we did not use them.
The patternToMatch is
ora_pmon_[(]?([^)]*)[)]?
The first part (ora_pmon_) is *literal*. That is, we need an exact match.
Anything inside square brackets is a character set. So [A-Z] is a range that would match ONE upper case letter. After the square brackets, there can be modifiers. A ? matches one optional character. A * matches one or more characters, and it will match ALL that it can - this is "greedy". So [(]? will match ONE left parenthesis IF it is present. If there is no left parenthesis, it will not match anything, but since that match was optional, this is not a failure. Likewise, [)]? is an optional match for a right parenthesis.
We can also negate patterns, or "not match", with the ^ at the start of a character set. So the [^)]* matches EVERYTHING until it hits a right paren. So this should match A1|A2|A3 or A1.
By putting a pattern inside parentheses, we tell perl to remember the resulting match, and make that available in the replacementText. The result from the first set of parens is available as \1, the second as \2, and so on.
So with input of "ora_pmon_A1", we match "ora_pmon_" with the literal characters. There is no left paren to (optionally) match. We match "A1" with the pattern in parens, so "A1" is now \1. There is no right paren to match. In the replacementText, we put in \1, which results in "A1" as output (replacement for $_).
With input of "ora_pmon_(A1|A2|A3}", we match "ora_pmon_" with the literal characters. We match the left paren. We match "A1|A2|A3" with the pattern in parens, so "A1!A2|A3" is now \1. We match the right paren. In the replacementText, we put in \1, which results in "A1" as output (replacement for $_).
HTH.
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-10-2003 09:50 AM
тАО07-10-2003 09:50 AM
Re: perl - substitution
though my head is still spinning, i got most of what you said.
now i need to do my home work.
-balaji
ps: am astonished by your patience in spending so much time to write a detailed reply. thanks a lot.