![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Covert Deci to Hex (New to AWK)
Hi, I am very new to awk and would be grateful for your help.
I need to convert a file with details like this, Wregister( 45676, 0) Wregister( 55550, 1) Wregister( 44000, 0) FlipFlop( 2342, 2) . . to look like this Wregister(626C, 0) Wregister(D8FE, 1) Wregister(ABE0, 0) FlipFlop( 2342, 2) -----> unchanged,name doesn't start with "Wregister(" . . It converts $2 in deci into hex, and then combines the previous $1 and $2 together. The (,) at the end of the numbers is a problematic one for me. It needs to be retained too. Please help me. |
|
||||
|
Quote:
linda.awk: Code:
BEGIN {
FS="[(,]"
OFS=","
}
$1 == "Wregister" {
$1 = sprintf("%s(%X", $1, $2)
$2=$3; NF--
}
1
|
|
|||
|
Hi vgersh99,
Thks for the help. I finally applied it succesfully today. But, here comes another seperate but related problem. This time, I tried to convert from a Hex to Deci number by creating a new script with "%d" on the hex number, but it failed. I need to convert a file with these, ABC c001 DEF ABC c050 EFG ABC c802 GHI to ABC 49153 DEF ABC 49232 EFG ABC 51202 GHI Please help me again. Thank you!! |
|
||||
|
Quote:
linda.awk: Code:
BEGIN {
for (i = 0; i < 10; i++)
hex[i] = i
hex["a"] = hex["A"] = 10
hex["b"] = hex["B"] = 11
hex["c"] = hex["C"] = 12
hex["D"] = hex["d"] = 13
hex["e"] = hex["E"] = 14
hex["f"] = hex["F"] = 15
}
function dehex(h, i,x) {
for (i = 1; i <= length(h); i++)
x = x*16 + hex[substr(h, i, 1)]
return x
}
{
$2 = dehex($2)
print
}
CompLangAWK on USENET |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Covert Channels Evaluation Framework 0.1 (Default branch) | Linux Bot | Software Releases - RSS News | 0 | 05-21-2008 09:40 PM |
| Covert rows into one line data | vj_76 | Shell Programming and Scripting | 8 | 06-14-2005 08:50 AM |
| Covert case of first letter only | tisons | Shell Programming and Scripting | 1 | 01-28-2005 06:13 AM |