Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.wizards Subject: Re: replacing nulls in a file with sed. Message-ID: <8872@jpl-devvax.JPL.NASA.GOV> Date: 25 Jul 90 20:58:23 GMT References: <1990Jul24.224811.22143@midway.uchicago.edu> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 29 In article <1990Jul24.224811.22143@midway.uchicago.edu> monty@delphi.uchicago.edu (Monty Mullig) writes: : i have a file that comes with null characters randomly placed in it. : i'd like to replace those nulls with spaces, but i can't seem to get : sed to do this. the command: : : sed 's/\(^@\)/ /g' < infile > outfile : : removes the nulls, but doesn't replace them with spaces. : in emacs, the null characters show up as ^@ characters and : global search and replace works (using the control-q to enter : ^@ as a true control character, rather than a carat and an : at sign). Most Unix utilities are not null-proof, because C doesn't make it real easy to be null-proof. Chances are the null isn't even making it past your shell! Even tr can't handle \000, seemingly. GNU emacs is a fortunate exception--so's Perl: perl -pe 's/\0/ /g' outfile or, a bit more efficiently perl -pe 'y/\0/ /' outfile Note also that you can specify the null in human-readable form with Perl. So you can sneak it right past your shell. Larry Wall lwall@jpl-devvax.jpl.nasa.gov