From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Jean-Fran=E7ois=20Blanchet?= Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: script for replacing Null character in files Date: Mon, 31 Mar 2003 14:11:22 -0500 Sender: tru64-unix-managers-owner@ornl.gov Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Trace: main.gmane.org 1049137964 26106 80.91.224.249 (31 Mar 2003 19:12:44 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 31 Mar 2003 19:12:44 +0000 (UTC) Original-X-From: tru64-unix-managers-owner-gotm-tru64-unix-managers=m.gmane.org@sws1.ctd.ornl.gov Mon Mar 31 21:12:42 2003 Return-path: Original-Received: from sws1.ctd.ornl.gov ([160.91.22.101]) by main.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 1904hJ-0006j5-00 for ; Mon, 31 Mar 2003 21:11:57 +0200 Original-Received: (qmail 21708 invoked by uid 5); 31 Mar 2003 19:11:58 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 21699 invoked by uid 49493); 31 Mar 2003 19:11:58 -0000 Original-Received: from Jfblanchet@dgeq.qc.ca by sws1 by uid 49491 with qmail-scanner-1.14 (clamscan: 0.54. spamassassin: 2.50-cvs. Clear:SA:0(0.6/5.0):. Processed in 0.53409 secs); 31 Mar 2003 19:11:58 -0000 Original-Received: from unknown (HELO emroute2.cind.ornl.gov) (160.91.86.17) by 0 with SMTP; 31 Mar 2003 19:11:57 -0000 Original-Received: from emroute2.cind.ornl.gov (LOCALHOST [127.0.0.1]) by emroute2.cind.ornl.gov (PMDF V6.2 #30669) with ESMTP id <0HCM00DN7NZUWQ@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Mon, 31 Mar 2003 14:11:57 -0500 (EST) Original-Received: from dgeq.qc.ca ([142.213.192.163]) by emroute2.cind.ornl.gov (PMDF V6.2 #30669) with SMTP id <0HCM00M6NNZN15@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Mon, 31 Mar 2003 14:11:48 -0500 (EST) Original-Received: from DGEQ-Message_Server by dgeq.qc.ca with Novell_GroupWise; Mon, 31 Mar 2003 14:11:26 -0500 Original-To: tru64-unix-managers@ornl.gov X-Mailer: Novell GroupWise 5.5.2 Content-Disposition: inline Xref: main.gmane.org gmane.os.tru64.managers:3844 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:3844 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 ; 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 main() { char ch =3D '\0'; char null =3D '\0'; char blank =3D ' '; while((ch =3D getc(stdin)) !=3D EOF) { if( ch !=3D null ) putc(ch,stdout); else putc(blank,stdout); } /* end of read loop */ fclose(stdout); /* so next program in pipe sees EOF properly */ } ---------------------------------------------------------------------------= ------------- =20