- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting questions
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
10-13-2003 11:49 AM
10-13-2003 11:49 AM
How do I write the below lines in PERL script.
line="/oracle/datafile/arclogs:"
HDR=`echo $line | cut -c 1-1`
HDR1=`echo $line | cut -f3 -d'/'`
HDR2=`echo $line | cut -f1 -d':'`
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2003 12:46 PM
10-13-2003 12:46 PM
Re: scripting questions
#!/usr/bin/perl
$line = "/oracle/datafiles/arclogs";
@HDR = split(/\//, $line);
print("$HDR[1]\n");
print("$HDR[2]\n");
print("$HDR[3]\n");
This will have 3 variables with name $HDR[1], $HDR[2], $HDR[3], where @HDR is the array.
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2003 05:37 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2003 02:37 AM
10-14-2003 02:37 AM
Re: scripting questions
Try this-
$line="/oracle/datafile/arclogs:";
($HDR2,$HDR,$HDR1)=$line=~m#^((.).+?/(.+?)/.+):#;
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2003 03:00 AM
10-14-2003 03:00 AM
Re: scripting questions
Maybe overkill for your example, but you can also import the File::Basename module which is part of a core Perl installation.
This exports for you among others the functions dirname() and basename() which should be familiar to you from shell scripting
(though uncalled for exporting isn't considered polite as CPAN standards go ;-)
You can read the docs by issuing
perldoc File::Basename
and if your interested in the implementation use the -m switch
perldoc -m File::Basename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2003 03:04 AM
10-14-2003 03:04 AM
Re: scripting questions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2003 04:33 AM
10-14-2003 04:33 AM
Re: scripting questions
Mark is correct, HDR should return '/' ,HDR2 should return 'datafile' and HDR2 should return everything before ':'.
I have written the script in kornshell but it tooks very time to complete. Perhap perl will give better performance.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2003 04:34 AM
10-14-2003 04:34 AM
Re: scripting questions
Mark is correct, HDR should return '/' ,HDR1 should return 'datafile' and HDR2 should return everything before ':'.
I have written the script in kornshell but it tooks very time to complete. Perhap perl will give better performance.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2003 05:12 AM
10-14-2003 05:12 AM
Re: scripting questions
my @p = ($path =~ m{(/[^/]*)}g);
lt09:/home/merijn 101 > perl -le'$path=shift;@p=($path=~m{(/[^/]*)}g);print for@p' /oracle/datafile/arclogs:
/oracle
/datafile
/arclogs:
lt09:/home/merijn 102 >
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2003 03:03 AM
10-15-2003 03:03 AM
Re: scripting questions
I admit I was too sloppy, not reading carefully enough the wanted result.
The only thing I wanted to stress is that whenever you can avoid Regexs, use functions like split(), or substr().
And if you can't or don't want to avoid them when you have a constant pattern, use the "o" modifier.
However, with the given result wanted you can avoid a regex, though admittedly by loss of elegance.
e.g.
$line = '/oracle/datafile/arclogs:';
($HDR, $HDR1, $HDR2) = (substr($line,0,1),(split(/\//,$line))[2],substr($line,0,
-1));