hex value in a file + perl


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers hex value in a file + perl
# 1  
Old 02-06-2007
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

Code:
>cat other
a|\xc2\xbo

Code:
>cat write.pl

#! /opt/third-party/bin/perl

open(FILE2, "< other") || die "Unable to open file other\n";
while ( chomp($content=<FILE2>) ) {
@split_arr = split(/\|/, $content);
}
close(FILE2);
                                                                                 
printf "%x", $split_arr[1];
                                                                                 
open(FILE1, "> output") || die "Unable to open file output\n";
print FILE1 "$split_arr[1]";
print FILE1 "\n";
close(FILE1);
                                                                                 
print "\n";


exit 0

# 2  
Old 02-06-2007
Code:
printf "%x", $split_arr[1];

Why are you trying to print \xc2\xbo with the specifier %x?
# 3  
Old 02-06-2007
Quote:
Originally Posted by anbu23
Code:
printf "%x", $split_arr[1];

Why are you trying to print \xc2\xbo with the specifier %x?
Yes,

it doesnt make sense to print hex value as a character using a hex format specifier.

Basic idea is I need to get ° printed in the stream / file without using the value as a perl string literal..

Hope I had made it clear !
# 4  
Old 02-06-2007
you could see even without "%x"

Code:
printf $split_arr[1];


required output is not obtained.


No way its displaying the required character.
# 5  
Old 02-06-2007
Quote:
Originally Posted by matrixmadhan
you could see even without "%x"

Code:
printf $split_arr[1];


required output is not obtained.


No way its displaying the required character.
I am getting the following output
Code:
\xc2\xbo

Is this what you need or something else?
# 6  
Old 02-06-2007
That is not the required output

If the hex value \xc2\xa9 is available in the file "other" ( as used in the script )

With the hex value I need to display the following symbol

©


into the file.

I dont want the hex value to be printed rather the corresponding character for the hex value.

Thanks!
# 7  
Old 02-06-2007
In addidtion to that,

When I use the hex value as perl string literal

Code:
my $var_194176_n = "\xc2\xb0";
print $var;

am getting the corresponding symbol as output.

When the same hex value retrieved from a configuration file and displayed only the hex value is printed and no character is displayed
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

[PERL] Convert TCP response to HEX

Dear community, I'm going crazy to convert TCP response to HEX using perl. I have a simple connection request where I send data, something like: use strict; use IO::Socket; my $sock; $sock = new IO::Socket::INET( PeerAddr => '192.168.10.7', PeerPort =>... (1 Reply)
Discussion started by: Lord Spectre
1 Replies

3. 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

4. Shell Programming and Scripting

Convert to Hex in perl

Hi, i want to convert number 5860533159 to hexadecimal. i need to use perl. i used $foo = 5860533159; $hexval3 = sprintf("%#x", $foo); i am getting value as 0xffffffff. i need to get value as 0x15D50A3A7. when i converted using google calculator, i got the correct value, expected... (9 Replies)
Discussion started by: asak
9 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Match hex value in string (Perl)

I am trying to match a character return from a website so that I can replace it. It is the '...' character (didnt even know it existed initially). The character apparently has the hex value of 2026, but in the script, attempting to substitute regular 3 periods is not working. What am I... (2 Replies)
Discussion started by: Guyverix
2 Replies

8. 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

9. Shell Programming and Scripting

parsing a hex file

Goodmorning, I have a hex encoded file that needs to be parsed to remove some bytes and write the remaining ones to a new file. Here is the top of the file as shown by a hex editor: http://www.wallpaperdepot.com/images/unix/TopofFile.gif The first parse exercise is to remove bytes 0-87... (6 Replies)
Discussion started by: philplasma
6 Replies

10. 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
Login or Register to Ask a Question