Re: base conversion inside awk?!?!?



On 15 Mrz., 10:14, "fazlin" <fazlin...@xxxxxxxxx> wrote:
Hi all,

Is there anyway to do base conversions (eg. decimal to hexa,

Use printf (or sprintf) with format specifier "%x".

binary to decimal etc.) inside awk.

Not that I am aware of any builtin. But you can write your own
function...

awk '{r=0;for(i=1;i<=length;i++){r*=2;r+=(substr($0,i,1)!="0")} print
r}'


Janis


Only way i could do was using system() cmd.

Plz lemme know if u have any inputs

Thanks,
Fazlin


.



Relevant Pages

  • Re: base conversion inside awk?!?!?
    ... Is there anyway to do base conversions (eg. decimal to hexa, ... Use printf (or sprintf) with format specifier "%x". ...
    (comp.unix.shell)
  • Re: One word to the right extreme and another to the left extreme
    ... any of the format specifier in printf:- ... If you want to know about printf formats and you are using ... It's a lousy non-portable suggestion relying on third-party ... He has not been posting here continuously. ...
    (comp.lang.c)
  • Re: sprintf and printf in Perl
    ... While 'printf' print the result directly to screen. ... sprintf and printf in Perl ... Output2 from screen (use sprintf for string) ... Useless use of sprintf in void context at math9.pl ...
    (perl.beginners)
  • Re: ISRT._DoSprintF
    ... Sprintf with "%n" Format Specifier Crashes Setup ... If szFormat includes the format specifier" %n", calling Sprintf or SprintfBox results in an unhandled exception "Error 0x80040707: ...
    (microsoft.public.de.german.windowsxp.setup)
  • setting MAX characters emitted in printf() functions?
    ... Where printf() here is generic and refers to sprintf, fprintf, etc. ... 256 characters on some platforms a double is even larger than that, ... string containing the formatted variable if the desired field ...
    (comp.lang.c)