LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-27-2004, 10:44 AM   #1
FoxyNewbie
LQ Newbie
 
Registered: May 2004
Posts: 3

Rep: Reputation: 0
Help! Null Characters to spaces


Im a newbie and need some help in understanding how to accomplish this task.

I have a file that contains this:
This is ly a TesT

In Hex this is what it looks like:
54 68 69 73 20 69 73 20 00 0E etc

I need to convert ALL 00 in a file to spaces.
I've been researching around and found that only certain SED's can do the job. Is there an AWK that can perform this functionality?

Thank in advance for your help.

FoxyNewbie
 
Old 05-27-2004, 11:11 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
I've been researching around and found that only certain SED's can do the job. Is there an AWK that can perform this functionality?
Sorry, I know too little about AWK.
But what's wrong with sed?
Code:
sed 's/\x00/ /g' file-with-zeroes >new-file-without-zeroes.txt
Works with GNU sed only I think, but probably that's most probably the sed that comes with your Linux distribution.

Last edited by Hko; 05-27-2004 at 11:15 AM.
 
Old 05-27-2004, 11:22 AM   #3
FoxyNewbie
LQ Newbie
 
Registered: May 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by Hko
Sorry, I know too little about AWK.
But what's wrong with sed?
Code:
sed 's/\x00/ /g' file-with-zeroes >new-file-without-zeroes.txt
Works with GNU sed only I think, but probably that's most probably the sed that comes with your Linux distribution.
Some versions of sed works but others does not.

When I pass through that specific code it still generates this in hex
Code:
sed 's/\x00/ /g' file-with-zeroes >new-file-without-zeroes.txt
00000000h: 54 68 69 73 20 69 73 20 00 6E 6C 79 20 61 20 74 ; This is .nly a t
00000010h: 65 73 74 ; est
 
Old 05-27-2004, 11:31 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Hmm, sorry about that.
 
Old 05-27-2004, 11:36 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Would the "strings" program help you out?
Try:

strings file-with-zeroes >new-file-without-zeroes
 
Old 05-27-2004, 11:38 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
If nothing comes up, I would happily write you a program in C that does it.
Just tell me.
 
Old 05-27-2004, 11:50 AM   #7
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
can you depend on perl? perl -pe 'tr/\000/ /' should do it
 
Old 05-27-2004, 12:10 PM   #8
FoxyNewbie
LQ Newbie
 
Registered: May 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by aluser
can you depend on perl? perl -pe 'tr/\000/ /' should do it
That code did it.

Thanks to everyone for your prompt reply.. this forum is the BEST!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
fstab-sync: error: libhal_ctx_init_direct: (null): (null) rpz Linux - Hardware 1 11-01-2005 05:42 AM
Way to many spaces LuderForChrist Linux - Newbie 4 06-25-2004 02:29 PM
spaces in a string Longinus Programming 18 03-08-2004 06:02 PM
spaces WindowsDefector Linux - Newbie 2 05-23-2002 02:03 AM
replace null characters in a file Philipp Programming 2 09-20-2001 02:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration