SED/AWK & null bytes

From: DAUBIGNE Sebastien - BOR ( SDaubigne@bordeaux-bersol.sema.slb.com ) (SDaubigne@bordeaux-bersol.sema.slb.com)
Date: Wed Feb 26 2003 - 10:13:07 EST


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@bordeaux-bersol.sema.slb.com
<mailto:sdaubigne@bordeaux-bersol.sema.slb.com>  - (+33)5.57.26.56.36
SchlumbergerSema - SGS/DWH/Pessac
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers


This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 23:25:53 EDT