HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh scripting question: - 101-105,119,164-16A
Operating System - HP-UX
1834254
Members
1836
Online
110066
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
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
Go to solution
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
04-21-2003 11:30 AM
04-21-2003 11:30 AM
I wrote a script to list EMC HyperVolumes in a volume group:
101 102 103 104 105 119 163 164 165 166 167 168 169 16A
For reporting purposes, I'd like to summarize the list like this:
101-105,119,164-16A
If it's sequential, summarize.
Can anyone help me do that? In ksh? or awk?
Stuart
101 102 103 104 105 119 163 164 165 166 167 168 169 16A
For reporting purposes, I'd like to summarize the list like this:
101-105,119,164-16A
If it's sequential, summarize.
Can anyone help me do that? In ksh? or awk?
Stuart
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2003 02:14 PM
04-21-2003 02:14 PM
Re: ksh scripting question: - 101-105,119,164-16A
Here is a perl routine...
foreach $n (@ARGV,FFFF) {
if (hex($prev)+1 == hex($n)) {
$prev=$n;
} else {
push(@list,($prev == $first ? $first : $first."-".$prev)) if $first;
$first=$n; $prev=$n;
}
}
print join(",",@list),"\n";
Run it by putting the above in a file (like rng.pl) and entering-
perl rng.pl 102 102 103 104 105 119 163 ...
result-
101-105,119,164-16A
HTH
-- Rod Hills
foreach $n (@ARGV,FFFF) {
if (hex($prev)+1 == hex($n)) {
$prev=$n;
} else {
push(@list,($prev == $first ? $first : $first."-".$prev)) if $first;
$first=$n; $prev=$n;
}
}
print join(",",@list),"\n";
Run it by putting the above in a file (like rng.pl) and entering-
perl rng.pl 102 102 103 104 105 119 163 ...
result-
101-105,119,164-16A
HTH
-- Rod Hills
There be dragons...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2003 12:57 AM
04-22-2003 12:57 AM
Solution
Hi Stuart,
Here's a ksh version of Rod's script:
=========================
#!/usr/bin/ksh
function add2string
{
if [ $to -eq $from ] ; then
s=$s$hfrom$sep
else
s=$s$hfrom-$hto$sep
fi
}
to=-1
sep=","
typeset -i10 n
for m in $*; do
p=16#${m}
let q=$to+1
if [ $p -eq $q ] ; then
to=$p
hto=$m
else
if [ $from ] ; then
add2string
fi
from=$p
hfrom=$m
to=$p
hto=$m
fi
done
sep=""
add2string
echo $s
===========================
Rod - your script needed a couple of mods to cater for when the first value is 1, and if the range was say, 1a-1c, i.e. $prev == $first would equate them as being equal, e.g.
===========================
$prev=FFFF;
foreach $n (@ARGV,FFFF) {
if (hex($prev)+1 == hex($n)) {
$prev=$n;
} else {
push(@list,(hex($prev) == hex($first) ? $first : $first."-".$prev)) if $first;
$first=$n; $prev=$n;
}
}
print join(",",@list),"\n";
===========================
rgds, Robin
Here's a ksh version of Rod's script:
=========================
#!/usr/bin/ksh
function add2string
{
if [ $to -eq $from ] ; then
s=$s$hfrom$sep
else
s=$s$hfrom-$hto$sep
fi
}
to=-1
sep=","
typeset -i10 n
for m in $*; do
p=16#${m}
let q=$to+1
if [ $p -eq $q ] ; then
to=$p
hto=$m
else
if [ $from ] ; then
add2string
fi
from=$p
hfrom=$m
to=$p
hto=$m
fi
done
sep=""
add2string
echo $s
===========================
Rod - your script needed a couple of mods to cater for when the first value is 1, and if the range was say, 1a-1c, i.e. $prev == $first would equate them as being equal, e.g.
===========================
$prev=FFFF;
foreach $n (@ARGV,FFFF) {
if (hex($prev)+1 == hex($n)) {
$prev=$n;
} else {
push(@list,(hex($prev) == hex($first) ? $first : $first."-".$prev)) if $first;
$first=$n; $prev=$n;
}
}
print join(",",@list),"\n";
===========================
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2003 04:39 AM
04-22-2003 04:39 AM
Re: ksh scripting question: - 101-105,119,164-16A
Thanks to both of you!
Stuart
Stuart
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 2025 Hewlett Packard Enterprise Development LP