Sponsored Content
Full Discussion: parsing a hex file
Top Forums Shell Programming and Scripting parsing a hex file Post 302304903 by quirkasaurus on Tuesday 7th of April 2009 02:17:15 PM
Old 04-07-2009
had a feeling. here it is in perl. not tooooo different:

Code:
#!perl


my $counter;
my $bytes_read;

#----------------------------------------------------------------------#
#  Argument check.                                                     #
#----------------------------------------------------------------------#
if ( scalar( @ARGV ) != 2 ){
  print "usage: $0 file-in file-out \n";
  exit(9);
  }

#----------------------------------------------------------------------#
#  Open files in binary mode...                                        #
#----------------------------------------------------------------------#
unless ( sysopen FIN, $ARGV[0], O_RDONLY ){
  print "cannot read file: $ARGV[0] \n";
  exit(9);
  }

unless ( sysopen FOUT, $ARGV[1], O_WRONLY ){
  print "cannot write to file: $ARGV[1] \n";
  exit(9);
  }

#----------------------------------------------------------------------#
#  Skip over first 88 bytes.                                           #
#----------------------------------------------------------------------#
sysseek FIN, 88, SEEK_SET;

$counter = 0;

#----------------------------------------------------------------------#
#  Read the file...                                                    #
#----------------------------------------------------------------------#
while ( $bytes_read = sysread FIN, $line, 1 ){

  $counter++;

#----------------------------------------------------------------------#
#  Skip the record past 512 bytes...                                   #
#----------------------------------------------------------------------#
  if ( $counter > 512 ){
    $counter = 0;
    while ( $bytes_read = sysread FIN, $line, 1 ){
      $counter++;
      last if ( $counter > 16 );
      }
    $counter = 0;
    }

#----------------------------------------------------------------------#
#  Write stuff.                                                        #
#----------------------------------------------------------------------#
  syswrite FOUT, $line, 1;

  } #-** while reading the input file. . .. **-#

close FIN;
close FOUT;

exit(0);


Last edited by quirkasaurus; 04-07-2009 at 03:18 PM.. Reason: error messages....
 

10 More Discussions You Might Find Interesting

1. HP-UX

Hex characters of ascii file

Hi, Whats the command or how do you display the hexadecimal characters of an ascii file. thanks Bud (2 Replies)
Discussion started by: budrito
2 Replies

2. UNIX for Dummies Questions & Answers

hex value in a file + perl

Am not able to display the corresponding character for the hex value using the format specifier into a file Could you please help me with that >cat other a|\xc2\xbo >cat write.pl #! /opt/third-party/bin/perl open(FILE2, "< other") || die "Unable to open file other\n"; while (... (7 Replies)
Discussion started by: matrixmadhan
7 Replies

3. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

4. Programming

After converting the hexstr to Hex and storing the Hex in a char*

Hi All, My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ',' This has to be done for all the hexstring char* is NULL. Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Discussion started by: rvan
1 Replies

5. Programming

What is the difference between ios::hex and std::hex?

Hi, Is there really a difference between these two, std::hex and ios::hex?? I stumbled upon reading a line, "std::ios::hex is a bitmask (8 on gcc) and works with setf(). std::hex is the operator". Is this true? Thanks (0 Replies)
Discussion started by: royalibrahim
0 Replies

6. Shell Programming and Scripting

Perl: Parse Hex file into fields

Hi, I want to split/parse certain bits of the hex data into another field. Example: Input data is Word1: 4f72abfd Output: Parse bits (5 to 0) into field word1data1=0x00cd=205 decimal Parse bits (7 to 6) into field word1data2=0x000c=12 decimal etc. Word2: efff3d02 Parse bits (13 to... (1 Reply)
Discussion started by: morrbie
1 Replies

7. Shell Programming and Scripting

Compare Hex Value from CSV File

I have a one CSV File Contain Hex Value here is a sample file 6300, 0x0, 0x60d0242c6, , 0x728e5806, unnamedImageEntryPoint_0x728e5806, 0x728e$ 6300, 0x0, 0x60d024c52, , 0x728e8cb7, unnamedImageEntryPoint_0x728e8cb7, 0x728e$ 6300, 0x0, 0x60d025638, , 0x728e82da,... (2 Replies)
Discussion started by: rakesh_arxmind
2 Replies

8. HP-UX

Replacing Hex Characters In A File Using awk?

Hi guys, First off, i'm a complete noob to UNIX and LINUX so apologies if I don't understand the basics! I have a file which contains a hex value of '0D' at the end of each line when I look at it in a hex viewer. I need to change it so it contains a hex value of '0D0A0A' I thought... (10 Replies)
Discussion started by: AndyBSG
10 Replies

9. Shell Programming and Scripting

Convert Binary File To Hex In Linux

dHi, I have the attached file(actual file can be extracted post unzipping it) & i am trying to use the following code for coversion to hex format. Starting hex value is 84 which is start of the record & termination is done using 00 00 followed by 84(hex) which i can see in the dump clearly using... (14 Replies)
Discussion started by: siramitsharma
14 Replies

10. Shell Programming and Scripting

Find and delete a certain HEX and its following value in a file

Hello there, I've been trying to do this half of the day and it's like I haven't come a single step further, so I hope you guys can help me with my problem: I have a text file that contains strings that should not be there and which I want to delete automatically from the command line. The... (4 Replies)
Discussion started by: surfi
4 Replies
HEXMERGE(1)						      General Commands Manual						       HEXMERGE(1)

NAME
hexmerge - Merge two or more GNU Unifont .hex font files into one. SYNOPSIS
hexmerge input_font1.hex input_font2.hex > output_font.bdf DESCRIPTION
hexmerge reads two or more GNU Unifont .hex file, sorts them, and writes the combined font to stdout. FILES
*.hex GNU Unifont font files SEE ALSO
bdfimplode(1), hex2bdf(1), hex2bdf-split(1), hex2sfd(1), hexbraille(1), hexdraw(1), johab2ucs2(1), unibmp2hex(1), unicoverage(1), unidup(1), unihex2bmp(1), unipagecount(1), uniunmask(1) AUTHOR
hexmerge was written by Roman Czyborra. LICENSE
hexmerge is Copyright (C) 1998 Roman Czyborra, and is released under the following terms (taken from http://czyborra.com): "All of my works you find here are freeware. You may freely copy, use, quote, modify or redistribute them as long as you properly attribute my contribution and have given a quick thought about whether Roman might perhaps be interested to read what you did with his stuff. Hori- zontal rules don't apply." BUGS
No known bugs exist. 2008 Jul 06 HEXMERGE(1)
All times are GMT -4. The time now is 07:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy