SUMMARY String Edit text file with nul characters

From: John W. Funk (
Date: Wed Aug 13 1997 - 11:36:52 CDT

Original question abbreviated
> I need to string edit (sed) text files without losing null characters. The
> "file" command says they are ascii text, but diff reports them as binary.
> When I edit the file with vi, it reports null characters, and when I write
> the file, they are lost. I have obtained nvi, which preserves the null
> characters, as "^@", and I am told textedit preserves them as well.
> How do I sed the text without losing null characters?

Solutions were sent in the same batch of mail as my request...
..... amazing list.

use perl to create new file,
  perl -p -e "s/^A/B/" file > newfile
or, to do the replacement in-place in the same file:
  perl -i -p -e "s/^A/B/" file
or another suggestion,
  perl -ne 's/^A/B/;print;' file > newfile

use gnu sed, (pkgadd format from
  gnused 's/^A/B/' file > newfile

Thanks to

Gene Rackow <>
Davin Milun <milun@cs.Buffalo.EDU>
Michael Maciolek <>
Daniel Kluge <>
Seth Rothenberg <>

and those whose replies are still on their way, thanks again.


John W. Funk, P.Eng voice: 905-829-5028
CAD/CAM & Unix Consultants Inc. fax: 905-829-0517
P.O. Box 61024, Maple Grove P.O. email:
Oakville, Ontario, Canada L6J 7P5

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:00 CDT