- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- search and replace the last character but counrtin...
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
тАО04-27-2011 05:45 AM
тАО04-27-2011 05:45 AM
my file looks like this:
map dev 16D3 to dir 10B:0 target=0 lun=267;
map dev 16D3 to dir 07B:1 target=0 lun=267;
map dev 16D3 to dir 04A:0 target=0 lun=267;
map dev 16D3 to dir 13A:1 target=0 lun=267;
map dev 16CB to dir 10B:0 target=0 lun=268;
map dev 16CB to dir 07B:1 target=0 lun=268;
map dev 16CB to dir 04A:0 target=0 lun=268;
map dev 16CB to dir 13A:1 target=0 lun=268;
map dev 16C3 to dir 10B:0 target=0 lun=269;
map dev 16C3 to dir 07B:1 target=0 lun=269;
map dev 16C3 to dir 04A:0 target=0 lun=269;
map dev 16C3 to dir 13A:1 target=0 lun=269;
map dev 0572 to dir 10B:0 target=0 lun=26A;
map dev 0572 to dir 07B:1 target=0 lun=26A;
map dev 0572 to dir 04A:0 target=0 lun=26A;
map dev 0572 to dir 13A:1 target=0 lun=26A;
with many more entries and I need to replace the lun=
ie starting with the stanza "map dev 16D3" I'd like to replace 267 with 2D3 then the next stanza entries 268 with 2D4
is it possible to count and report in hex?
any ideas are greatly appreciated :)
Thanks
Chris
Solved! Go to Solution.
- Tags:
- hex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 05:56 AM
тАО04-27-2011 05:56 AM
Solution"..unsigned hexadecimal notation using (x and X)..."
for example:
printf "%5x" $DEC_NUM
##############
There is 'dc' - do a man dc
h1 = "echo 16i " toupper($1) " pq | dc"
###############
There is awk
awk '{print ("0x"$1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 06:26 AM
тАО04-27-2011 06:26 AM
Re: search and replace the last character but counrting in hex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 06:30 AM
тАО04-27-2011 06:30 AM
Re: search and replace the last character but counrting in hex
I am also sure there is a pearl version but I also found an awk and can incorporate this with the "sub" routine within awk
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 06:35 AM
тАО04-27-2011 06:35 AM
Re: search and replace the last character but counrting in hex
Yes, you can do arithmetic in hexadecimal :-)
If I understand correctly, this is what you want:
# cat ./myconverter
#!/usr/bin/perl
use strict;
use warnings;
my ($old, $new) = ( "267", "2D3" );
my $diff = hex($new) - hex($old);
while (<>) {
s/(lun=)([0-9a-fA-F]+);$/sprintf("%s%X;",$1,hex($2)+$diff)/xe and print;
}
1;
...run as:
# ./myconverter file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 09:18 AM
тАО04-27-2011 09:18 AM
Re: search and replace the last character but counrting in hex
:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 08:21 PM
тАО04-27-2011 08:21 PM
Re: search and replace the last character but counrting in hex
typeset -i10 lun=16#2d3
awk -F= -v start=$lun <
/map dev 16D3/ { replace = 1 }
length($0) == 0 && replace { ++start } # gap
{
if ($0 ~ /map dev/ && replace) {
printf "%s=%s=%X;\n",$1,$2, start
} else
print $0
} ' file
- Tags:
- awk