- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Dec to hex with awk
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
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
тАО08-26-2004 03:55 AM
тАО08-26-2004 03:55 AM
I can convert from hex to dec but I seem to get lost from dec to hex within "AWK". Harry once showed me the hex to dec.
Any Ideas
Many Thanks
Chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 04:14 AM
тАО08-26-2004 04:14 AM
Re: Dec to hex with awk
eg:
echo 10 | awk '{printf("%x\n",$1)}'
a
echo 11 | awk '{printf("%x\n",$1)}'
b
echo 244 | awk '{printf("%x\n",$1)}'
f4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 04:25 AM
тАО08-26-2004 04:25 AM
Re: Dec to hex with awk
Thanks
What how about if I got it in a function and need to define it so as to printf it. e.g
###########################
function get_info(file)
###########################
{
e_b="LookFor"
SEA="*"$6"."$7"
{if (match($7,"swing")){
TOOL="/usr/bin/which CheckFor "
TOOL | getline TOOL2;close(TOOL)
#this is where I need to substr and the convert to Dec
Once Again Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 04:30 AM
тАО08-26-2004 04:30 AM
Re: Dec to hex with awk
You can also do with adb.
echo "0D
-- Sundar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 04:46 AM
тАО08-26-2004 04:46 AM
Re: Dec to hex with awk
Within an awk program/script just use 'sprintf' to print to a string:
awk 'BEGIN{x=sprintf("%0X",30);print x,x,x}'
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 05:08 AM
тАО08-26-2004 05:08 AM
Re: Dec to hex with awk
Thanks that was great,(rusting). What if I have a date 20040818040320
YER=sprintf("%s",(substr($1,3,2)))
MON=sprintf("%0x",(substr($1,5,2)))
DAY=sprintf("%0x",(substr($1,7,2))) (this will be 18 = 12
HH=sprintf("%0x",(substr($2,7,2))) 04 = 4
etc
I would like to define it a the end e.g
YMDHMS= YERMONDAYHH so as to used it for a search pattern.
In the hour (04), converting it to dec will be 4 (048124) which is what I am not looking for. What I would like the result to be "040812040332"
Any Ideas
Thanks Again
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 05:55 AM
тАО08-26-2004 05:55 AM
SolutionNow you confused me on when you are goign from hex to dec or back. Still, never mind, the basic formatting principle apply:
For example "%02X"
% = format coming up!
0 = leading 0 requestion
2 = fieldsize 2
X = upcased hexadecimal (vs x for lower, and d for decimal)
And you can combine lots of formats, with lots of (prefereably as many :-) input in a single sprintf giving something like:
echo "20040818040320" | awk '{x=sprintf("%s%02X%02X%02d",substr($1,3,2),substr($1,5,2),substr($1,7,2),substr($1,9,2));print x}'
You'll have to verify spaces and X and d usage.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 06:53 AM
тАО08-26-2004 06:53 AM
Re: Dec to hex with awk
Great explanation with 10. Its all coming back to me.
Anyway Thanks to all role players.
Chris