Nothing stupid about them...

...I just stole the name from David Letterman's "stupid pet tricks". I hope these tips help you avoid or fix mistakes along the way in your *nix administration duties.

Thursday, June 17, 2010

Deleting NULL characters

If you ever need to process files from a mainframe, it's likely you will come across a file with lots of NULL characters (ASCII 0).

These characters appear in vi or other editors like this:

^@^@^@^@^@^@^@^@^@^@^@

Ugh.

You can use your old friend sed(1) to get rid of them, but you have to match the pattern of the NULL character. And how do you pass that to sed?

sed -e 's/\o00//g' infile > outfile

That pattern says match octal number 00 and replace it with nothing.

0 comments:

Search

Google