Change Hex character strings to HTML entities


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change Hex character strings to HTML entities
# 1  
Old 04-12-2010
Change Hex character strings to HTML entities

Hi!

I am not a whiz at awk and very unsure about the aplication of awk solve my problem. I was hoping for some quick pointers so I can figure this out.

I have a file that looks like so:
Code:
label.Asked=\u8CEA\u554F\u6E08\u307F
button.Edit=\u7DE8\u96C6
data.menu.WorkWeekProfile=<li>\u5E73\u65E5\u30D7<b>\u30ED\u30D5</b>\u30A3\u30FC\u30EB</li>

Now, I want this to be changed into:
Code:
label.Asked=&#x8CEA;&#x554F;&#x6E08;&#x307F;<br />
button.Edit=&#x7DE8;&#x96C6;<br />
data.menu.WorkWeekProfile=<li>&#x5E73;&#x65E5;&#x30D7;<b>&#x30ED;&#x30D5;</b>&#x30A3;&#x30FC;&#x30EB;</li><br />

Notice that I want to change each unicode value to its HTML entity form, while adding a BR tag at the end of each line so it is formatted appropriately in HTML.

A simple find replace does not work since I have to work around already embedded HTML tags. Any help is much apreciated!

Last edited by pinnochio; 04-12-2010 at 05:33 PM.. Reason: Updated source
# 2  
Old 04-12-2010
Why is this line treated differently?

Code:
data.menu.WorkWeekProfile=<li>&#x5E73;&#x65E5;&#x30D7;<b>&#x30ED;&#x30D5;</b>&#x30A3;&#x30FC;&#x30EB;</li><br />

I see that you added additional <li> and <b> tags.
# 3  
Old 04-12-2010
I am so sorry, I just fixed my original post. The source file also has the HTML tags in it.

Quote:
Originally Posted by pinnochio
Hi!
Code:
data.menu.WorkWeekProfile=<li>\u5E73\u65E5\u30D7<b>\u30ED\u30D5</b>\u30A3\u30FC\u30EB</li>

# 4  
Old 04-12-2010
Hello, pinocchio:

Code:
$ cat data
label.Asked=\u8CEA\u554F\u6E08\u307F
button.Edit=\u7DE8\u96C6
data.menu.WorkWeekProfile=<li>\u5E73\u65E5\u30D7<b>\u30ED\u30D5</b>\u30A3\u30FC\u30EB</li>

$ sed 's/\\u\([[:xdigit:]]\{4\}\)/\&#x\1;/g; s/$/<br \/>/' data
label.Asked=&#x8CEA;&#x554F;&#x6E08;&#x307F;<br />
button.Edit=&#x7DE8;&#x96C6;<br />
data.menu.WorkWeekProfile=<li>&#x5E73;&#x65E5;&#x30D7;<b>&#x30ED;&#x30D5;</b>&#x30A3;&#x30FC;&#x30EB;</li><br />

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract expressions between two strings in html file

Hello guys, I'm trying to extract all the expressions between the following tags: <b></b> from a HTML file. This is how it looks: big lines containing several dozens expressions (made of 1,2,3,4,6 or even 7 words) I would like to extract: <b>bla ble</b>bla ble</td><tr valign="top"><td... (3 Replies)
Discussion started by: bobylapointe
3 Replies

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

3. UNIX for Dummies Questions & Answers

character-by-character comparison of strings

This might be a dummy question, but is there a command in UNIX that compare two strings character-by-character and display the difference? ---------- Post updated at 11:25 AM ---------- Previous update was at 10:32 AM ---------- Or probably what I'm looking is how to break a string into... (3 Replies)
Discussion started by: Orbix
3 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. UNIX for Dummies Questions & Answers

Getting strings before and after a character

OK This one has me stumped. I have the following line, program name - the program description that can also contain a hyphen - character. I'm need to separate the "program name" from the program description. I've tried using an array function with the - as delimiter, but I ran into a... (2 Replies)
Discussion started by: ricksj
2 Replies

6. UNIX for Dummies Questions & Answers

Help to replace character strings

Hello Can Any1 help me. I want to replace a specific character string inside a file at a specific location with a particular character with the help of a command or a shell script. The tr command replaces a specific character with another for all the occurences of that character in the file. I... (5 Replies)
Discussion started by: rahulrathod
5 Replies

7. UNIX for Advanced & Expert Users

Convert UTF-8 encoded hex value to a character

Hi, I have a non-ascii character (Ŵ), which can be represented in UTF-8 encoding as equivalent hex value (\xC5B4). Is there a function in unix to convert this hex value back to display the charcter ? (10 Replies)
Discussion started by: sumirmehta
10 Replies

8. UNIX for Dummies Questions & Answers

delete newline character between html tags

Hi, I have learned some of the Unix commands a way back and not sure of how to code them when needed in certain way, especially sed command. Here is my situation. I have an xml file with several tags. most of the tags start on the same line and end on the same line. However, data for some tags... (8 Replies)
Discussion started by: girish312
8 Replies

9. UNIX for Dummies Questions & Answers

How do I get past an HTML::entities discrepancy on an RPM?

I have an RPM that I am trying to install and it keeps coming back with: I know I could kill the bird by throwing a "yum install *perl*" at it, but this seems like hurling a skyscraper at an ant... any better suggestions? (2 Replies)
Discussion started by: jjinno
2 Replies

10. Shell Programming and Scripting

Looking for a hex character?

Hi guys , i would want to count the concurrences of the 0A hex char in a text file , then if no matches i need to add a 0A at the end of the line. Any ideas? thx.Regards (1 Reply)
Discussion started by: Klashxx
1 Replies
Login or Register to Ask a Question