Printing NULL (binary 0) in awk 
Author Message
 Printing NULL (binary 0) in awk

The subject sez it all.  I need to be able to print every character from
0-255 in standard awk.  The reason is that the awk program must run on
many different platforms (including some very old ones) unmodified &
uses the least common denominator - plain old awk.

gawk handles it just fine of course.   What I've tried without success
is:

printf("%c",0)
printf("\000")

even created a file with a null byte in it & tried to read it in with

"cat nul" |readline nul

Any ideas?



Mon, 30 Apr 2001 03:00:00 GMT  
 Printing NULL (binary 0) in awk

Quote:

> The subject sez it all.  I need to be able to print every character from
> 0-255 in standard awk.  The reason is that the awk program must run on
> many different platforms (including some very old ones) unmodified &
> uses the least common denominator - plain old awk.

When assuming plain old awk, you have to accept that it is simply
not possible to print 0 bytes. This is the most annoying disadvantage
of awk that I ever encountered.

Quote:

> gawk handles it just fine of course.   What I've tried without success
> is:

Indeed, gawk is wonderful. With gawk, I can even run my script that
turns ASCII time series data into .WAV files (sounds).

Quote:

> Any ideas?

Yes, I once used

  dd bs=1 count=1 < /dev/zero > file0.bin

with a system() command. This way, you have at least a file with the
0 byte available. But this is not a solution for the original problem.

+---------------------------------------------------------------------+
| Juergen Kahrs,       STN Atlas Elektronik GmbH,   D-28305 Bremen    |
| Simulation Division  Sebaldsbruecker Heerstr. 235 +49/421/457-2819  |
+----------- http://home.t-online.de/home/Juergen.Kahrs/ -------------+



Tue, 01 May 2001 03:00:00 GMT  
 Printing NULL (binary 0) in awk

maybe this helps:
--------------------
awk '{  nul=sprintf("%c",0)
             string=$0 nul
             print string
          }'

not tested
 LMS
free sed/awk book:
      ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/1997/97-2-007.ps.gz
      ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/1997/97-2-007.tar.gz



Wed, 02 May 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. awk sees too many NULLs

2. Awk truncates lines (encounters null)

3. Binary scan and NULL-char

4. Bug/Feature?: regsub stops at binary strings containing NULL character

5. Reading binary data containing nulls

6. DOS Print Null Terminated String ????????

7. Expect: abort upon printing to /dev/null??

8. Exclude Nulls (in Key definition): what is Null?

9. Null Record is not always Null

10. NULL statements, NULL values, and teaching

11. win32com support for NULL bstr, NULL com object

 

 
Powered by phpBB® Forum Software