- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- PERL: need a script to manipulate binary files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2005 02:59 PM
тАО07-14-2005 02:59 PM
without any respect to syntax, this is what I am trying to accomplish:
offset=variable1
length=variable2
open_for_read (INHANDLE, inputfile)
open_for_write (OUTHANDLE, outputfile)
rec=read (INHANDLE, offset, length)
write (OUTFILE, rec)
my PERL programming skills is one step far from none-existent. So far any kind of perl for beginners type document I could find online and off, talks about opening and reading from text files. I know this is what PERL is designed for but wondering if there is any way to read a binary file byte-by-byte. If yes, how can I do this ?
All in all what I am trying to do is to chop up some binary files into several smaller chunks, and copying them into my windows machine and using one of those splitters does not work for me. The commercial products are designed to chop up the stuff into smaller fixed size chunks and it is not what I am looking for.
As always thanks in advance...
UNIX because I majored in cryptology...
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2005 04:47 PM
тАО07-14-2005 04:47 PM
Solutionmy $length = $ENV{variable2}; # length in environment variable
my $file = $ARGV[0]; # filename passed as first command line argument
open my $filehandle, "< $file" or die "$file: $!";
open my $ofile, "+< file.out" or die "file.out: $!";
my $buffer;
seek $filehandle, $offset, 0;
read $filehandle, $buffer, $length;
seek $ofile, 1245, 0; # write at position 1245
syswrite $ofile, $buffer;
close $filehandle;
close $ofile;
Don't forget to count the newline characters in your offsets
Proof of concept:
lt09:/tmp 115 > cat xx.txt
0123456789
1234567890
lt09:/tmp 116 > cat yy.txt
0123456789
1234567890
lt09:/tmp 117 > perl -we'open$in,"
0123456789
1234567890
lt09:/tmp 119 > cat yy.txt
0123456789
5674567890
lt09:/tmp 120 >
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 06:51 AM
тАО07-15-2005 06:51 AM
Re: PERL: need a script to manipulate binary files
dd bs=1 skip=bytes_to_skip if=file1 > file2
Whereas bytes_to_skip is n blocks to skip, and since we are setting the block size to 1 byte, it will skip n bytes.
dd is quite efficient for these type of tasks and is available on just about every Unix system out of the box.
Here is an example:
# dd bs=1 skip=3 if=usflag.gif > x.gif
9347+0 records in
9347+0 records out
# ls -al usflag.gif x.gif
-rwxr--r-- 1 ths staff 9350 Sep 17 2001 usflag.gif
-rw-rw-r-- 1 ths staff 9347 Jul 15 16:48 x.gif
You'll see that the binary file is 3 bytes smaller, which are removed from the beginning according to the skip directive to dd.
-- Tom
- Tags:
- dd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 07:15 AM
тАО07-15-2005 07:15 AM
Re: PERL: need a script to manipulate binary files
Check the dd man page for more info.
Hope this helps...
-- Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2005 07:36 AM
тАО07-15-2005 07:36 AM
Re: PERL: need a script to manipulate binary files
Thanks for pointing out the dd option. Never crossed my mind prior to reading it here.
UNIX because I majored in cryptology...