LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-21-2010, 11:13 AM   #1
Alkass
Member
 
Registered: Mar 2010
Posts: 47

Rep: Reputation: 0
sed including ± symbol


Hi again!

I have a file with lines like

268.903± 1.893(ab)
270.01± 2.6(fb)

what I want to do is

1-sed and if (ab) is found, replace (ab) AND ± with E10-6
2-sed and if (fb) is found replace (fb) AND ± with E10-3

so output looks like

268.903E10-6 1.893E10-6
270.01E10-3 2.6E10-3

I have problem replacing the ± symbol correctly....

Thanks in advance!
A
 
Old 04-21-2010, 02:30 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
What have you tried so far? GNU sed can replace hexadecimal values, so that the problem could be reduced to identify the correct hex sequence to match the ± symbol (od or hexdump might come in handy).
 
Old 04-21-2010, 03:22 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
According to hexdump, the symbol is 0xc2 + 0xb1. I cannot find it in the unicode tables,

I found various hints that Gnu SED will recognize unicode, but no concrete examples.

Regardless, this works: (I put the 2 sample lines into a file named "hex")
Code:
[mherring@mystical play]$ more hex
268.903± 1.893(ab)
270.01± 2.6(fb)
[mherring@mystical play]$ sed 's/\xc2\xb1/here/' hex
268.903here 1.893(ab)
270.01here 2.6(fb)
 
1 members found this post helpful.
Old 04-22-2010, 01:38 AM   #4
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by pixellany View Post
According to hexdump, the symbol is 0xc2 + 0xb1. I cannot find it in the unicode tables
C2 B1 is the UTF-8 encoding of the character U+00B1, which is indeed the ± sign.-
 
Old 04-22-2010, 02:59 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Dan04 View Post
C2 B1 is the UTF-8 encoding of the character U+00B1, which is indeed the ± sign.-
Good to know. I've just found a complete UTF-8 character set online, here.

An off-topic note: Gnome terminal (and maybe many others) supports UTF-8 typing: we have to press simultaneously Ctrl-Shft, type u followed by the Unicode number, release Ctrl-Shift and the UTF-8 character appears. Even the LQ Reply box in Firefox supports it... ± ♥
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
symbol lookup error: /usr/lib/libavcodec.so.51: undefined symbol: av_crc04C11DB7 priceey Linux - Software 0 05-06-2009 08:14 AM
./firefox-bin :symbol lookup error:/lib/libgthread-2.0.so.0: undefined symbol: arulupsaras Linux - General 1 11-08-2008 04:48 AM
symbol lookup error: /usr/lib/libgtk-x11.2.0.so.0: undefined symbol:... IamI Slackware 17 02-29-2008 11:10 AM
Workaround: 'symbol lookup error: k3b: undefined symbol: lstat64' devdol Linux - Software 2 02-15-2008 03:36 AM
insert a symbol with sed tonton Programming 5 08-31-2004 11:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration