Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jagardn

macrumors 6502a
Original poster
Apr 18, 2011
668
2
Ok, I have a file with a bunch of nulls(0x00) that I want to strip out. The solution should be somewhat simple, but yet doesn't work the way I thought it would.
sed 's/\x00/~/g' should replace every null character with a ~, but yet it does nothing. At first I thought it was a problem with null characters, but I tried the same with \x0D (Carriage Return) and it didn't work either. Any ideas?
 
Had to write a script to get it done. Mods can close the thread. Thanks

Code:
!/bin/bash

# Script Variables

INCLUDEFILE="./Note.fil"
OUTFILE="./outfile.csv"
TMPFILE="./tmp.txt"
FILESIZE=`ls -l | awk '/\ Note.fil/ {print $5}'`
BYTESIZE=1536
RECORDS=$(( ($FILESIZE / BYTESIZE) -1 ))
CUSTOMER=0
NOTES=""

# Script Main
clear
echo "\"CUSTID\",\"NOTES\"" > $OUTFILE
for (( c=0; c<=$RECORDS; c++ ))

    do
        #Increment CustomerID for cvs export
        CUSTOMER=$(( $c + 1 ))
        #Clear display and show progress of the import
        clear
        echo "Importing Record Number $CUSTOMER to $OUTFILE"
        #use dd to get the data in 1526 byte increments, skip blocks determined by "$c" variable
        dd if=./Note.fil of=./tmp.txt bs=1536 count=1 skip=$c > /dev/null 2>&1
        #use strings binary to extract the nulls from the file
        NOTES=`strings $TMPFILE`
        #use tr to remove <CR><LF> from data strings and replace with spaces
        NOTES=`tr '\r\n' '  ' < $TMPFILE`
        #Send formatted csv data to output file
        echo "\"$CUSTOMER\",\"$NOTES\"" >> $OUTFILE

done
exit 0
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.