SUMMARY String Edit text file with nul characters

From: John W. Funk (jwf@ccuc.on.ca)
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 http://smc.vnet.net/solaris_2.5.html)
  gnused 's/^A/B/' file > newfile

Thanks to

Gene Rackow <rackow@mcs.anl.gov>
Davin Milun <milun@cs.Buffalo.EDU>
Michael Maciolek <mikem@centerline.com>
Daniel Kluge <danielk@tibco.com>
Seth Rothenberg <SROTHENB@montefiore.org>

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

jwf

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: jwf@ccuc.on.ca
Oakville, Ontario, Canada L6J 7P5



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