Find the answer to your Linux question:
Results 1 to 4 of 4
Hi All, I have a text file and it appears the text inside is encoded in Ascii. The file is filled with numbers that I have to take from a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Location
    Toronto, Canada
    Posts
    8

    Dump text file in binary format


    Hi All,
    I have a text file and it appears the text inside is encoded in Ascii. The file is filled with numbers that I have to take from a URL, so it just ends up being saved as Ascii.

    Would anyone here know how I could dump this text as binary/hex?

    The contents of the file will be input into a program that evaluates randomness of data and Ascii skews the results because of the additional data it adds to each character.

    Any help is much appreciated.

    Thanks,
    Vivek

  2. #2
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    280
    I'm not sure if this is what you're looking for, but try
    Code:
    od -h FILE.txt
    "man 1 od" for more help.

  3. #3
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    280
    ...Ascii skews the results because of the additional data it adds to each character.
    This puzzles me, because ASCII *IS* just hex 01 to 7F. It adds no additional data to characters. Perhaps you mean unicode or UTF-8 instead of ASCII?

  4. #4
    Just Joined!
    Join Date
    Oct 2007
    Location
    Toronto, Canada
    Posts
    8
    Quote Originally Posted by Miven View Post
    This puzzles me, because ASCII *IS* just hex 01 to 7F. It adds no additional data to characters. Perhaps you mean unicode or UTF-8 instead of ASCII?
    So, I needed the output without any encoding, including ASCII. ASCII encoding does seem to add some bits. In my example, I have a file with one unsigned integer per line. Open the file in a hex editor, I use Okteta. The hex values shown there are not real conversions from integer to hex. The representation in the file is such that humans can read. What I need is a machine level file with all numbers represented in hex with no special characters or new lines. Just a bit stream.

    A friend of mine helped me out. This is what did it (perl).

    Code:
    while (<ASCII_FILE>){
    	$line=$_;
    	chomp ($line);
    	print $out pack("i*",$line);
    	my $ascii_value=chomp($line);	
    }
    close ($out);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •