I have a 3 gig binary file that I need to edit. I'm running into memory problems since I have to pack and unpack the file. I've tried running on a unix, linux and windows machine with no luck. Any ideas on what I can do? I basically need to open the file and edit it at a bit level. I need to find certain bit patterns and remove them. I've tried to edit using hex characters but have found when I remove the character instead of only 8 bits being removed 16 get removed. Have no idea why that happens.
Per requests below is the code:
#!/usr/local/bin/perl -w undef $/; #Clear the record seperator. $| = 1; #Don't Buffer data. Write out when available. open IN, "$ARGV[0]"; binmode IN; #Use binary mode so windows/DOS won't complain #Convert original file into binary and write to $final while (<IN>) { #Loop thru file and convert file to 1's/0's $array = unpack("B*", $_); open OUT, ">>tmp"; print OUT "$array"; close OUT; undef $array; } close IN; print "Finished unpacking data.\n\n"; undef $/; open IN, "tmp"; #Extract the necessary data bits while (<IN>) { $_ =~ s/11110100.{8}(.{1520})11110100.{8}(.{464}).{1056}/$1$2/g; $final - pack("B*", $_); #Conver data back to original binary for +mat open OUT, ">>$ARGV[1]"; print OUT "$final"; close OUT; undef $final; } close IN; unlink "tmp"; print "Finished converting to binary.\n\n";
20041021 Janitored by Corion: Added formatting
In reply to Out of memory problems by tperdue
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |