[SunHELP] SED/AWK & null bytes

DAUBIGNE Sebastien - BOR ( SDaubigne@bordeaux-bersol.sema.slb.com ) SDaubigne at bordeaux-bersol.sema.slb.com
Wed Feb 26 09:13:07 CST 2003


Are you aware of any Solaris tool that handles null bytes properly ?
I need to substitute regular expressions in files with null bytes, and I
can't make sed/awk work well with it (I guess it is due to the terminating
null bytes of libC strings).
SED removes null bytes in the line, as do TR.
AWK truncates the bytes after the null byte in the line.

The only solution I've found is to make a C program which substitutes null
bytes by any non-null bytes not found in the file (e.g. '%'), then sed/awk,
then substitute back the non-null byte by null-byte.

> echo "aaa\0bbb" | sed 's/a/f/g' |od -c    
0000000   f   f   f   b   b   b  \n

> echo "aaa\0bbb" | nawk '{gsub("a","f");print}' |od -c
0000000   f   f   f  \n

---
Sebastien DAUBIGNE 
sdaubigne at bordeaux-bersol.sema.slb.com
<mailto:sdaubigne at bordeaux-bersol.sema.slb.com>  - (+33)5.57.26.56.36
SchlumbergerSema - SGS/DWH/Pessac


More information about the SunHELP mailing list