SUMMARY: script for replacing Null character in files

From: Jean-François Blanchet <Jfblanchet_at_dgeq.qc.ca>
Date: Mon, 31 Mar 2003 14:11:22 -0500

My question:

   I want to find and replace ascii character 00 by blank in file.

   I have 125 files to do.

   Can you give me a solution with unix utilities?

Solutions:

A lot of good responses,
but I have use this one:


perl -pi -e 's/\x00/ /g;' filename

Using wildcards in the filename is valid, too.

------------------------------------------------------------------
for i in <filelist>; do tr "\0" " " <$i >$i.nonul; cp $i.nonul $i; rm -f
$i.nonul; done;

------------------------------------------------------------------
foreach x (*)
  echo $x
  cat $x | tr '\000' ' ' > ${x}.NEW
  mv $x.NEW $x
end
------------------------------------------------------------------
/*
    chnulltoblank.c
    P. Farrell, Jan 15, 2003

    Program to read std input, translate all null characters
(\000) to blanks, and write to standard output.

    Compile with:
        cc -o chnulltoblank chnulltoblank.c

    Use like this:
        chnulltoblank < inputfile > outputfile
*/
#include <stdio.h>

main()
{
   char ch = '\0';
   char null = '\0';
   char blank = ' ';

   while((ch = getc(stdin)) != EOF) {

      if( ch != null )
    putc(ch,stdout);
      else
    putc(blank,stdout);

   } /* end of read loop */

   fclose(stdout); /* so next program in pipe sees EOF properly */
}

----------------------------------------------------------------------------------------


   
Received on Mon Mar 31 2003 - 19:12:28 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:44 NZDT