ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
That's because you are feeding in a string representation - you can use hex values directly in the sed substitution by using \x.. (or octal \o).
There something wrong if that (dec) number is supposed to be a single byte. Somebody that understands the myriad codepages might be able to explain that to you.
$ cat 272.pl
#!/usr/bin/perl
while ($_ = <>) {
s/\\272//gs;
print $_, "\n";
}
$ cat infile
Hello Wor\272ld! It's a \272Small World After\272 All! Though the oceans are wide and the mountains divide, \272It's \272A Small World After \272All!
$ ./272.pl < infile > outfile
$ cat outfile
Hello World! It's a Small World After All! Though the oceans are wide and the mountains divide, It's A Small World After All!
$
A single byte has the numeric range 0..255, and does not include characters such as the one you mention.
Therefore, we know that it is a Unicode character, and that it is being represented in the UTF-8 encoding scheme as (in this case ....) a pair of bytes.
Any UTF-aware "search and replace in a string" function should be able to accomplish this job trivially ... and, today, most of them are. (But you might in some cases have to select UTF-encoding.)
The OP used od -xc which produces sequences of 4 hex digits, single letters, and 3 octal digits. Therefore, '272', being 3 digits, is most likely on octal number.
Code:
$ printf $'\272etc' | od -xc
0000000 65ba 6374
272 e t c
0000004
The OP used od -xc which produces sequences of 4 hex digits, single letters, and 3 octal digits. Therefore, '272', being 3 digits, is most likely on octal number.
(Very respectfully ...) The OP also originally described "the character that (s)he was actually seeing" as: "The character looks like an A with a caret on top with a degree sign to the right. Thus, I must assume that the reference is to the binary value of the first of two bytes which actually comprise the character. The WikiPedia article on 'UTF-8' describes this multi-byte encoding scheme in detail.
(Best-guess as to the actual character: "Á")
Last edited by sundialsvcs; 06-02-2017 at 08:48 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.