Bin files saved as txt.. Convert

A place For General Chit Chat Etc
User avatar
Jayme
Posts: 2585
Joined: Sun Mar 01, 2009 8:59 am
Location: North Coast, NSW

Re: Bin files saved as txt.. Convert

Post by Jayme »

its less a formula and more a process... there are better easier ways of doing it but I was bored. you have to split it into 5 or so sections as excel runs out of resources (at least on my pc) after about 10,000 rows.
paste data into cell A2, in cell B2 use formula =B1&A2 then double click the little square in the corner to fill down the formula. scroll to the last row to get hte whole long string, then copy that and paste into your hex editor. make sure the last byte in the string you copied isnt one character.



I would use one of the perl scripts if there were heaps to fix.
User avatar
festy
Posts: 1039
Joined: Sat Apr 30, 2011 6:27 pm
cars: Alfa Romeos
Location: Narellan, NSW

Re: Bin files saved as txt.. Convert

Post by festy »

well if you're using windows, replace "cat" with "type" and you'll be in business

the | feeds the output of "type 84.txt" to perl (i.e the contents of the txtfile), the "-e" flag is for "read the perl commands from the cmdline" and -n is "assume a while() loop around reading the input lines", chomp takes care of the CR/LF, chr prints the character specified by the ascii number following, which is wrapped in a hex() to convert the contents of the line from hexadecimal to suit the chr command if that makes it any clearer? ;)
VX L67 Getrag
Posts: 2883
Joined: Sun Aug 02, 2009 9:16 pm
Location: Bayside, Melbourne, Victoria
Contact:

Re: Bin files saved as txt.. Convert

Post by VX L67 Getrag »

Clear as MUD, no seriously I'll look into it when I get a chance again (my parts just arrived been waiting all day 1st lot they sent were wrong).

Jayme, yeah it would probably max out this PC's resources too so need to split it up, but I also need to find out how to use more of excel's formulas as there's kalmaker dif files that I'd love to seperate each line into columns & sure excel could do it but haven't figured it out yet!
User avatar
antus
Site Admin
Posts: 8253
Joined: Sat Feb 28, 2009 8:34 pm
cars: TX Gemini 2L Twincam
TX Gemini SR20 18psi
Datsun 1200 Ute
Subaru Blitzen '06 EZ30 4th gen, 3.0R Spec B
Contact:

Re: Bin files saved as txt.. Convert

Post by antus »

haha, i used bash and sed and padded/aligned with dd, went to post back and Jaymes answer was in :lol:

Code: Select all

$ cat hex2bin
#!/bin/bash
echo -n -e $(tr -d '[:space:]' | sed 's/../\\x&/g')
$ cat OLD\ VS\ \$84\ File.txt | ./hex2bin > 84fixed.bin
$ (dd if=/dev/zero count=24576 bs=1 ; cat 84fixed.bin) > 84fixed2.bin
$ ls -l 84fixed2.bin
-rw-r--r-- 1 ant ant 65536 Dec 14 14:11 84fixed2.bin
Have you read the FAQ? For lots of information and links to significant threads see here: http://pcmhacking.net/forums/viewtopic.php?f=7&t=1396
User avatar
festy
Posts: 1039
Joined: Sat Apr 30, 2011 6:27 pm
cars: Alfa Romeos
Location: Narellan, NSW

Re: Bin files saved as txt.. Convert

Post by festy »

you could have also used dd's seek= arg to write to the correct offset, but that's pretty neat anyway :thumbup:
I was going to use s+a, but after being up working all night I chose the easiest option ;)
User avatar
Holden202T
Posts: 10311
Joined: Sat Feb 28, 2009 9:05 pm
Location: Tenambit, NSW
Contact:

Re: Bin files saved as txt.. Convert

Post by Holden202T »

:? :? :? :? :?
VX L67 Getrag
Posts: 2883
Joined: Sun Aug 02, 2009 9:16 pm
Location: Bayside, Melbourne, Victoria
Contact:

Re: Bin files saved as txt.. Convert

Post by VX L67 Getrag »

My thoughts exactly 202.... LMAO seriously when I get a chance have to look into perl!

just as a matter of interest is there a way of laying a kalmaker dif file out so it displays each section in it's own column?

LMAO... I just figured out something for myself & it was quite easy....

It's an excel DATA option called text to column & BINGO all sorted easy as!
User avatar
festy
Posts: 1039
Joined: Sat Apr 30, 2011 6:27 pm
cars: Alfa Romeos
Location: Narellan, NSW

Re: Bin files saved as txt.. Convert

Post by festy »

Seeing as you've got perl and a bunch of those text files to convert, here's a script that will convert them for you (and pad them if needed).

Code: Select all

C:\festy>perl txt2binfile.pl "OLD VS $84 File.txt"
bin size is 49152 bytes, pad the start to 65536? (y/N)y
OLD VS $84 File.bin created
Attachments
txt2binfile.pl
(1.34 KiB) Downloaded 224 times
VX L67 Getrag
Posts: 2883
Joined: Sun Aug 02, 2009 9:16 pm
Location: Bayside, Melbourne, Victoria
Contact:

Re: Bin files saved as txt.. Convert

Post by VX L67 Getrag »

YOUR A LEGEND Festy, Thanks so much thats awesome now I'll go dig perl off other HDD!

Thanks a bunch, let me know if there's anything I can do for you!

EDIT: the 2 versions of PERL i have are DZPERL58 or Strawberry PERL 5.10.0.6, are either of these any good it was years ago I got them?
User avatar
antus
Site Admin
Posts: 8253
Joined: Sat Feb 28, 2009 8:34 pm
cars: TX Gemini 2L Twincam
TX Gemini SR20 18psi
Datsun 1200 Ute
Subaru Blitzen '06 EZ30 4th gen, 3.0R Spec B
Contact:

Re: Bin files saved as txt.. Convert

Post by antus »

Yeah for perl on windows generally its good to use the latest strawberry perl. (though if that script doesnt run on it because its too new, use the older version you have).
http://strawberryperl.com/
Have you read the FAQ? For lots of information and links to significant threads see here: http://pcmhacking.net/forums/viewtopic.php?f=7&t=1396
Post Reply