GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Remving the 1st letter of word in perl
Operating System - HP-UX
1846983
Members
3478
Online
110257
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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-10-2010 02:52 AM
11-10-2010 02:52 AM
Remving the 1st letter of word in perl
Hi All,
In one of the sections in my perl script, I need to remove the 1st character of a word and store in an array.The details are ,
The original script was ,
if ( ! defined $inq{$node}{"dmx"} ) {
print "INFO: Collecting inq disk information for DMX array on $node.\n";
$command="/opt/admin/bin/inq -sym_wwn -nodots |grep dsk";
my @clarinq;
($rcode, @clarinq) = execute_command($node, $command, "root");
#print Dumper @clarinq;
my ($ldev, $disk, $diskdevice, $line);
foreach $line (@clarinq) {
($diskdevice, $junk, $ldev, $junk) = split (/\s+/, $line);
($junk, $junk, $junk, $disk) = split (/\//, $diskdevice);
#print "disk is $disk, ldev is $ldev\n";
$inq{$node}{"dmx"}{$disk}=$ldev;
}
}
The o/p of /opt/admin/bin/inq -sym_wwn -nodots |grep dsk is in the format,
# /opt/admin/bin/inq -sym_wwn -nodots |grep dsk
/dev/rdsk/c25t0d0 000290103691 1C4D 60060480000290103691533031433444
The 3rd column is storing to "ldev".
In the new servers, the above inq command is not workin.We have the new command and the o/p of that command is in the format is,
$ pbrun /opt/admin/bin/inq.HPUXIA64 -sym_wwn -nodots|grep disk|grep -v HP |more
/dev/rdisk/disk8 000290103691 0237A 60060480000290103691533032333741
The 3rd column is of 5 digit and I want to remvoe the 1st character so that it will be in the same format as that of old servers.
I have tried this way.....
if ( ! defined $inq{$node}{"dmx"} ) {
print "INFO: Collecting inq disk information for DMX array on $node.\n";
$command="/opt/admin/bin/inq.HPUXIA64 -sym_wwn -nodots|grep disk|grep -v HP";
my @clarinq;
($rcode, @clarinq) = execute_command($node, $command, "root");
#print Dumper @clarinq;
my ($ldev, $disk, $ldev1, $diskdevice, $line);
foreach $line (@clarinq) {
($diskdevice, $junk, $ldev1, $junk) = split (/\s+/, $line);
($junk, $junk, $junk, $disk) = split (/\//, $diskdevice);
($junk, $ldev, $ldev, $ldev, $ldev) =split (/c/, $ldev1);=> This is not taking
#print "disk is $disk, ldev is $ldev\n";
$inq{$node}{"dmx"}{$disk}=$ldev;
}
}
Please could any one help me .
Ahilash
In one of the sections in my perl script, I need to remove the 1st character of a word and store in an array.The details are ,
The original script was ,
if ( ! defined $inq{$node}{"dmx"} ) {
print "INFO: Collecting inq disk information for DMX array on $node.\n";
$command="/opt/admin/bin/inq -sym_wwn -nodots |grep dsk";
my @clarinq;
($rcode, @clarinq) = execute_command($node, $command, "root");
#print Dumper @clarinq;
my ($ldev, $disk, $diskdevice, $line);
foreach $line (@clarinq) {
($diskdevice, $junk, $ldev, $junk) = split (/\s+/, $line);
($junk, $junk, $junk, $disk) = split (/\//, $diskdevice);
#print "disk is $disk, ldev is $ldev\n";
$inq{$node}{"dmx"}{$disk}=$ldev;
}
}
The o/p of /opt/admin/bin/inq -sym_wwn -nodots |grep dsk is in the format,
# /opt/admin/bin/inq -sym_wwn -nodots |grep dsk
/dev/rdsk/c25t0d0 000290103691 1C4D 60060480000290103691533031433444
The 3rd column is storing to "ldev".
In the new servers, the above inq command is not workin.We have the new command and the o/p of that command is in the format is,
$ pbrun /opt/admin/bin/inq.HPUXIA64 -sym_wwn -nodots|grep disk|grep -v HP |more
/dev/rdisk/disk8 000290103691 0237A 60060480000290103691533032333741
The 3rd column is of 5 digit and I want to remvoe the 1st character so that it will be in the same format as that of old servers.
I have tried this way.....
if ( ! defined $inq{$node}{"dmx"} ) {
print "INFO: Collecting inq disk information for DMX array on $node.\n";
$command="/opt/admin/bin/inq.HPUXIA64 -sym_wwn -nodots|grep disk|grep -v HP";
my @clarinq;
($rcode, @clarinq) = execute_command($node, $command, "root");
#print Dumper @clarinq;
my ($ldev, $disk, $ldev1, $diskdevice, $line);
foreach $line (@clarinq) {
($diskdevice, $junk, $ldev1, $junk) = split (/\s+/, $line);
($junk, $junk, $junk, $disk) = split (/\//, $diskdevice);
($junk, $ldev, $ldev, $ldev, $ldev) =split (/c/, $ldev1);=> This is not taking
#print "disk is $disk, ldev is $ldev\n";
$inq{$node}{"dmx"}{$disk}=$ldev;
}
}
Please could any one help me .
Ahilash
- Tags:
- Perl
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2010 05:23 AM
11-10-2010 05:23 AM
Re: Remving the 1st letter of word in perl
Ahilash,
Thanks for a well presented problem.
The new device names are for the new 'agile', access path independent name.
If there is a 5th digit, it might be needed at some point in time... you realize that right?
anyway, i would suggest that instead of the repeat split you look for patterns instead.
You want
$1) the part after the last part in the first word
$2) the last 4 hex-characters in the 3rd word. An optional leading char
Using your 2 examples i van get that with:
$ perl -ne 'print qq($1 $2\n) if /^.*?(\/\w+)\s+\w+\s+.?([0-9A-F]{4})\s/' x.x
/c25t0d0 1C4D
/disk8 237A
^.*?(\/\w+)\s+ = remember last part of first word
\w+\s+ = second word
.?([0-9A-F]{4})\s = remember 4 chars in range, followed by whitespace, with optional '?' anything char.
In your code that can be used as:
if (/^.*?(\/\w+)\s+\w+\s+.?([0-9A-F]{4})\s/) {
$disk = $1;
$ldev = $2;
:
Good luck!
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2010 05:32 AM
11-10-2010 05:32 AM
Re: Remving the 1st letter of word in perl
Hi:
> The 3rd column is of 5 digit and I want to remvoe the 1st character so that it will be in the same format as that of old servers.
If I understand correctly, you want lines like:
/dev/rdisk/disk8 000290103691 0237A 60060480000290103691533032333741
...changed to:
/dev/rdisk/disk8 000290103691 237A 60060480000290103691533032333741
For this, you could do:
# X="/dev/rdisk/disk8 000290103691 0237A 60060480000290103691533032333741"
# echo $X|perl -pe 's/(.+?\s)(.+?\s).(....)/$1$2$3/'
By the way, instead of doing:
# ($junk, $junk, $junk, $disk) = split (/\//, $diskdevice)
...use an array slice and do:
# $disk = (split /\//, $diskdevice)[3];
Regards!
...JRF...
> The 3rd column is of 5 digit and I want to remvoe the 1st character so that it will be in the same format as that of old servers.
If I understand correctly, you want lines like:
/dev/rdisk/disk8 000290103691 0237A 60060480000290103691533032333741
...changed to:
/dev/rdisk/disk8 000290103691 237A 60060480000290103691533032333741
For this, you could do:
# X="/dev/rdisk/disk8 000290103691 0237A 60060480000290103691533032333741"
# echo $X|perl -pe 's/(.+?\s)(.+?\s).(....)/$1$2$3/'
By the way, instead of doing:
# ($junk, $junk, $junk, $disk) = split (/\//, $diskdevice)
...use an array slice and do:
# $disk = (split /\//, $diskdevice)[3];
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2010 05:50 AM
11-10-2010 05:50 AM
Re: Remving the 1st letter of word in perl
my typos:
part after the last part --> part after the last slash
i van --> I can
Your subject line indicated...
>> Remving the 1st letter of word in perl
Fortunately the body of the topic explained clearly what the real problem was that you were trying to solve.... retain the last 4 :-)
If one comes looking here for either those questions, then here is one of many ways how to do that.
remove first: $x =~ s/.//;
retain last 4: $y =~ s/.*(....)/$1/
In a working example:
$ perl -e '$x = $y = q(abcdefgh); $x =~ s/.//; $y =~ s/.*(....)/$1/; print qq($x $y\n)'
Other common ways to solve this and similar problems is to use the SUBSTR function, perhaps with the help of LENGTH to find where to start/end.
Hein
part after the last part --> part after the last slash
i van --> I can
Your subject line indicated...
>> Remving the 1st letter of word in perl
Fortunately the body of the topic explained clearly what the real problem was that you were trying to solve.... retain the last 4 :-)
If one comes looking here for either those questions, then here is one of many ways how to do that.
remove first: $x =~ s/.//;
retain last 4: $y =~ s/.*(....)/$1/
In a working example:
$ perl -e '$x = $y = q(abcdefgh); $x =~ s/.//; $y =~ s/.*(....)/$1/; print qq($x $y\n)'
Other common ways to solve this and similar problems is to use the SUBSTR function, perhaps with the help of LENGTH to find where to start/end.
Hein
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP