Sponsored Content
Top Forums UNIX for Advanced & Expert Users unable to extract Trademark(™) Character Post 302231243 by era on Tuesday 2nd of September 2008 01:50:32 AM
Old 09-02-2008
The big question is in which character set you do see the trademark sign, or, which ISO-8859-1 character are you seeing as a SUB character (whatever that is?)

In ASCII there is a control character SUB (ctrl-Z) which has the character code 26 decimal (octal 032, hex 0x1A) -- is that what you have in your file? What would be a useful encoding to transfer it to? The following will translate all occurrences of this character code into the Unicode trade mark symbol character U+2122 in the UTF-8 encoding:

Code:
perl -pe 's/\x1A/\xE2\x84\xA2/g' file.orig > file.utf8

Or in ISO-8859-1, there is the Registered sign ® at code point 0xAE, would that be a useful substitute?

Code:
perl -pe 's/\x1A/\xAE/g' file.orig > file.iso-8859-1

This assumes that the SUB character really is character code 0x1A; if it's not, but you can find out what it is instead, it should be trivial to adapt either of these one-liners to something which works for you. Some Windows code pages have the trademark symbol at 0x99 so that might be a thing to try if 0x1A doesn't work for you (but again, if you can look at the raw bytes in the file, you don't have to guess).

Last edited by era; 09-02-2008 at 02:59 AM.. Reason: Add ISO8859-1 ® substitution; remark on Windows 0x99 character
 

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Extract a character

HI Guys, Have a Doubt...... I have a pattern "abcdef" and i need to extract the third character..ie(c) How to achieve it? (10 Replies)
Discussion started by: aajan
10 Replies

2. Shell Programming and Scripting

extract character + 1

Hi, I would like extract from a file a character or pattern after ( n + 1) a specific pattern (n) . ( i supposed with awk) how could i do ? Thanks in advance. (1 Reply)
Discussion started by: francis_tom
1 Replies

3. Shell Programming and Scripting

Unable to read special character from the file

Hello All, We are getting files from sftp server through file transmission protocol & after transmission we are removing all the control M (^M) characters from them.we are expecting various kind of special characters in the files. we are tried removing '^M' characters through 'dos2unix' command... (2 Replies)
Discussion started by: Aquilis
2 Replies

4. UNIX for Dummies Questions & Answers

Unable to extract bz2-00 file

I have a file having name smthing.tar.bz2-00 I am trying to unzip it using tar -xvjf "name" But I am not able to unzip it. PLease advise for the issue. (3 Replies)
Discussion started by: nixhead
3 Replies

5. Programming

Unable to assign zero to unsigned character array

Hi, I am unable to assign value zero to my variable which is defined as unsigned char. typedef struct ABCD { unsigned char abc; unsigned char def; unsigned char ghi; } ABCD; typedef ABCD *PABCD; In my Por*C code, i assign the values using memcpy like below ... (3 Replies)
Discussion started by: gthangav
3 Replies

6. Red Hat

Unable to extract .gz file using gunzip

Linux 3.8.13-16.2.1.el6uek.x86_64 #1 SMP Thu Nov 7 17:01:44 PST 2013 x86_64 x86_64 x86_64 GNU/Linux Hi all, I am unable to extract .gz file using gunzip Used the following command to create the .gz file: nohup tar -cvpf - 11.2.0.4 | gzip -c >... (3 Replies)
Discussion started by: a1_win
3 Replies

7. UNIX for Beginners Questions & Answers

Unable to create new user without lower character

Hi friends, I want to create new user BG0001 in SunOS and getting below errorbash-3.2# useradd -d /home/BG0001 -m -s /bin/sh BG0001 UX: useradd: BG0001 name should have at least one lower case character. bash-3.2# bash-3.2# OS version is as belowbash-3.2# cat /etc/release ... (7 Replies)
Discussion started by: sandeepkmehra
7 Replies
Encode::PerlIO(3pm)					User Contributed Perl Documentation				       Encode::PerlIO(3pm)

NAME
Encode::PerlIO -- a detailed document on Encode and PerlIO Overview It is very common to want to do encoding transformations when reading or writing files, network connections, pipes etc. If Perl is configured to use the new 'perlio' IO system then "Encode" provides a "layer" (see PerlIO) which can transform data as it is read or written. Here is how the blind poet would modernise the encoding: use Encode; open(my $iliad,'<:encoding(iso-8859-7)','iliad.greek'); open(my $utf8,'>:utf8','iliad.utf8'); my @epic = <$iliad>; print $utf8 @epic; close($utf8); close($illiad); In addition, the new IO system can also be configured to read/write UTF-8 encoded characters (as noted above, this is efficient): open(my $fh,'>:utf8','anything'); print $fh "Any x{0021} string N{SMILEY FACE} "; Either of the above forms of "layer" specifications can be made the default for a lexical scope with the "use open ..." pragma. See open. Once a handle is open, its layers can be altered using "binmode". Without any such configuration, or if Perl itself is built using the system's own IO, then write operations assume that the file handle accepts only bytes and will "die" if a character larger than 255 is written to the handle. When reading, each octet from the handle becomes a byte-in-a-character. Note that this default is the same behaviour as bytes-only languages (including Perl before v5.6) would have, and is sufficient to handle native 8-bit encodings e.g. iso-8859-1, EBCDIC etc. and any legacy mechanisms for handling other encodings and binary data. In other cases, it is the program's responsibility to transform characters into bytes using the API above before doing writes, and to transform the bytes read from a handle into characters before doing "character operations" (e.g. "lc", "/W+/", ...). You can also use PerlIO to convert larger amounts of data you don't want to bring into memory. For example, to convert between ISO-8859-1 (Latin 1) and UTF-8 (or UTF-EBCDIC in EBCDIC machines): open(F, "<:encoding(iso-8859-1)", "data.txt") or die $!; open(G, ">:utf8", "data.utf") or die $!; while (<F>) { print G } # Could also do "print G <F>" but that would pull # the whole file into memory just to write it out again. More examples: open(my $f, "<:encoding(cp1252)") open(my $g, ">:encoding(iso-8859-2)") open(my $h, ">:encoding(latin9)") # iso-8859-15 See also encoding for how to change the default encoding of the data in your script. How does it work? Here is a crude diagram of how filehandle, PerlIO, and Encode interact. filehandle <-> PerlIO PerlIO <-> scalar (read/printed) / Encode When PerlIO receives data from either direction, it fills a buffer (currently with 1024 bytes) and passes the buffer to Encode. Encode tries to convert the valid part and passes it back to PerlIO, leaving invalid parts (usually a partial character) in the buffer. PerlIO then appends more data to the buffer, calls Encode again, and so on until the data stream ends. To do so, PerlIO always calls (de|en)code methods with CHECK set to 1. This ensures that the method stops at the right place when it encounters partial character. The following is what happens when PerlIO and Encode tries to encode (from utf8) more than 1024 bytes and the buffer boundary happens to be in the middle of a character. A B C .... ~ x{3000} .... 41 42 43 .... 7E e3 80 80 .... <- buffer ---------------> << encoded >>>>>>>>>> <- next buffer ------ Encode converts from the beginning to x7E, leaving xe3 in the buffer because it is invalid (partial character). Unfortunately, this scheme does not work well with escape-based encodings such as ISO-2022-JP. Line Buffering Now let's see what happens when you try to decode from ISO-2022-JP and the buffer ends in the middle of a character. JIS208-ESC x{5f3e} A B C .... ~ e $ B |DAN | .... 41 42 43 .... 7E 1b 24 41 43 46 .... <- buffer ---------------------------> << encoded >>>>>>>>>>>>>>>>>>>>>>> As you see, the next buffer begins with x43. But x43 is 'C' in ASCII, which is wrong in this case because we are now in JISX 0208 area so it has to convert x43x46, not x43. Unlike utf8 and EUC, in escape-based encodings you can't tell if a given octet is a whole character or just part of it. Fortunately PerlIO also supports line buffer if you tell PerlIO to use one instead of fixed buffer. Since ISO-2022-JP is guaranteed to revert to ASCII at the end of the line, partial character will never happen when line buffer is used. To tell PerlIO to use line buffer, implement ->needs_lines method for your encoding object. See Encode::Encoding for details. Thanks to these efforts most encodings that come with Encode support PerlIO but that still leaves following encodings. iso-2022-kr MIME-B MIME-Header MIME-Q Fortunately iso-2022-kr is hardly used (according to Jungshik) and MIME-* are very unlikely to be fed to PerlIO because they are for mail headers. See Encode::MIME::Header for details. How can I tell whether my encoding fully supports PerlIO ? As of this writing, any encoding whose class belongs to Encode::XS and Encode::Unicode works. The Encode module has a "perlio_ok" method which you can use before applying PerlIO encoding to the filehandle. Here is an example: my $use_perlio = perlio_ok($enc); my $layer = $use_perlio ? "<:raw" : "<:encoding($enc)"; open my $fh, $layer, $file or die "$file : $!"; while(<$fh>){ $_ = decode($enc, $_) unless $use_perlio; # .... } SEE ALSO
Encode::Encoding, Encode::Supported, Encode::PerlIO, encoding, perlebcdic, "open" in perlfunc, perlunicode, utf8, the Perl Unicode Mailing List <perl-unicode@perl.org> perl v5.14.2 2006-05-03 Encode::PerlIO(3pm)
All times are GMT -4. The time now is 10:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy