<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic PERL: need a script to manipulate binary files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912739#M703207</link>
    <description>I am in search of a script or set of commands in PERL (or any other scripting language for that matter) which will open a binary file, read certain number of bytes, skipping over an offset # of bytes from the beginning, and write these bytes into another file.&lt;BR /&gt;&lt;BR /&gt;without any respect to syntax, this is what I am trying to accomplish:&lt;BR /&gt;&lt;BR /&gt;offset=variable1&lt;BR /&gt;length=variable2&lt;BR /&gt;open_for_read (INHANDLE, inputfile)&lt;BR /&gt;open_for_write (OUTHANDLE, outputfile)&lt;BR /&gt;rec=read (INHANDLE, offset, length)&lt;BR /&gt;write (OUTFILE, rec)&lt;BR /&gt;&lt;BR /&gt;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 ? &lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;As always thanks in advance...</description>
    <pubDate>Thu, 14 Jul 2005 21:59:48 GMT</pubDate>
    <dc:creator>Mel Burslan</dc:creator>
    <dc:date>2005-07-14T21:59:48Z</dc:date>
    <item>
      <title>PERL: need a script to manipulate binary files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912739#M703207</link>
      <description>I am in search of a script or set of commands in PERL (or any other scripting language for that matter) which will open a binary file, read certain number of bytes, skipping over an offset # of bytes from the beginning, and write these bytes into another file.&lt;BR /&gt;&lt;BR /&gt;without any respect to syntax, this is what I am trying to accomplish:&lt;BR /&gt;&lt;BR /&gt;offset=variable1&lt;BR /&gt;length=variable2&lt;BR /&gt;open_for_read (INHANDLE, inputfile)&lt;BR /&gt;open_for_write (OUTHANDLE, outputfile)&lt;BR /&gt;rec=read (INHANDLE, offset, length)&lt;BR /&gt;write (OUTFILE, rec)&lt;BR /&gt;&lt;BR /&gt;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 ? &lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;As always thanks in advance...</description>
      <pubDate>Thu, 14 Jul 2005 21:59:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912739#M703207</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-07-14T21:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: PERL: need a script to manipulate binary files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912740#M703208</link>
      <description>my $offset = 45; # offset hard coded&lt;BR /&gt;my $length = $ENV{variable2}; # length in environment variable&lt;BR /&gt;my $file = $ARGV[0]; # filename passed as first command line argument&lt;BR /&gt;&lt;BR /&gt;open my $filehandle, "&amp;lt; $file" or die "$file: $!";&lt;BR /&gt;open my $ofile, "+&amp;lt; file.out" or die "file.out: $!";&lt;BR /&gt;&lt;BR /&gt;my $buffer;&lt;BR /&gt;seek $filehandle, $offset, 0;&lt;BR /&gt;read $filehandle, $buffer, $length;&lt;BR /&gt;&lt;BR /&gt;seek $ofile, 1245, 0; # write at position 1245&lt;BR /&gt;syswrite $ofile, $buffer;&lt;BR /&gt;&lt;BR /&gt;close $filehandle;&lt;BR /&gt;close $ofile;&lt;BR /&gt;&lt;BR /&gt;Don't forget to count the newline characters in your offsets&lt;BR /&gt;&lt;BR /&gt;Proof of concept:&lt;BR /&gt;&lt;BR /&gt;lt09:/tmp 115 &amp;gt; cat xx.txt&lt;BR /&gt;0123456789&lt;BR /&gt;1234567890&lt;BR /&gt;lt09:/tmp 116 &amp;gt; cat yy.txt&lt;BR /&gt;0123456789&lt;BR /&gt;1234567890&lt;BR /&gt;lt09:/tmp 117 &amp;gt; perl -we'open$in,"&lt;XX.TXT&gt;&lt;/XX.TXT&gt;lt09:/tmp 118 &amp;gt; cat xx.txt&lt;BR /&gt;0123456789&lt;BR /&gt;1234567890&lt;BR /&gt;lt09:/tmp 119 &amp;gt; cat yy.txt&lt;BR /&gt;0123456789&lt;BR /&gt;5674567890&lt;BR /&gt;lt09:/tmp 120 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Thu, 14 Jul 2005 23:47:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912740#M703208</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2005-07-14T23:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: PERL: need a script to manipulate binary files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912741#M703209</link>
      <description>If you want to do this with just a shell command instead of perl:&lt;BR /&gt;&lt;BR /&gt;dd bs=1 skip=bytes_to_skip if=file1 &amp;gt; file2&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;dd is quite efficient for these type of tasks and is available on just about every Unix system out of the box.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Here is an example:&lt;BR /&gt;&lt;BR /&gt;# dd bs=1 skip=3 if=usflag.gif &amp;gt; x.gif&lt;BR /&gt;9347+0 records in&lt;BR /&gt;9347+0 records out&lt;BR /&gt;# ls -al usflag.gif x.gif&lt;BR /&gt;-rwxr--r--   1 ths        staff         9350 Sep 17  2001 usflag.gif&lt;BR /&gt;-rw-rw-r--   1 ths        staff         9347 Jul 15 16:48 x.gif&lt;BR /&gt;&lt;BR /&gt;You'll see that the binary file is 3 bytes smaller, which are removed from the beginning according to the skip directive to dd.&lt;BR /&gt;&lt;BR /&gt;-- Tom</description>
      <pubDate>Fri, 15 Jul 2005 13:51:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912741#M703209</guid>
      <dc:creator>Tom Schroll</dc:creator>
      <dc:date>2005-07-15T13:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: PERL: need a script to manipulate binary files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912742#M703210</link>
      <description>Ooops, in my dd example, I also forgot to include the count=n option, which will also control how many bytes are read in, so you can control the size.  Using a combination of skip and count, you should be able to break up binary files into pieces relatively efficiently.&lt;BR /&gt;&lt;BR /&gt;Check the dd man page for more info.&lt;BR /&gt;&lt;BR /&gt;Hope this helps...&lt;BR /&gt;&lt;BR /&gt;-- Tom</description>
      <pubDate>Fri, 15 Jul 2005 14:15:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912742#M703210</guid>
      <dc:creator>Tom Schroll</dc:creator>
      <dc:date>2005-07-15T14:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: PERL: need a script to manipulate binary files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912743#M703211</link>
      <description>Both solutions worked great.&lt;BR /&gt;&lt;BR /&gt;Thanks for pointing out the dd option. Never crossed my mind prior to reading it here.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Jul 2005 14:36:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-need-a-script-to-manipulate-binary-files/m-p/4912743#M703211</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-07-15T14:36:30Z</dc:date>
    </item>
  </channel>
</rss>

