Help with escaping xml characters in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with escaping xml characters in a file
# 1  
Old 02-07-2011
Help with escaping xml characters in a file

Hi,

I have a file xy.csv with the following data separated by pipe (|):

BC-NACO|12>ISA43<TEST|
A & A INC|FAMOUS'S AL|

i need to escape the xml characters as below

BC-NACO|12&gt;ISA43&lt;TEST|
A &amp; A INC|FAMOUS&apos;S AL|

Please advise
# 2  
Old 02-07-2011
Sorry, I answered too quickly.

Last edited by KenJackson; 02-07-2011 at 07:43 AM..
# 3  
Old 02-07-2011
Code:
 $ ruby -r'cgi' -ne 'puts CGI.escapeHTML($_)' file 
BC-NACO|12>ISA43<TEST| 
A & A INC|FAMOUS'S AL|

# 4  
Old 02-07-2011
You may also need to escape the spaces. Here is a solution using ksh93's printf "%H":
Code:
$ cat infile
BC-NACO|12>ISA43<TEST|
A & A INC|FAMOUS'S AL|

$ printf "%H\n" "$(<infile)"
BC-NACO|12&gt;ISA43&lt;TEST|
A&nbsp;&amp;&nbsp;A&nbsp;INC|FAMOUS&apos;S&nbsp;AL|
$

# 5  
Old 02-08-2011
None of the above solutions are working. i dont want to escape the spaces.
# 6  
Old 02-08-2011
Code:
sed "s/\&/\&amp;/;s/>/\&gt;/;s/</\&lt;/;s/'/\&apos;/" infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

French Accented characters in xml file comes as numbers

Hello all, I am using AIX 7.1 and whenever xml files with accented French characters are read, for example Name Andree where the first e has accented mark on top, AIX should it as Andrée but it comes as funny number characters for the first e. What do I need to fix this. I want to test with one... (5 Replies)
Discussion started by: pregmi
5 Replies

2. Shell Programming and Scripting

Find out special characters from xml file

Hi....I have a xml file which is having lots of special characters which I need to find out and put the distinct list of those into a text file. The list of special characters is not specific, it can be anything at different point of time. Can anyone help me to find out the same and list out? ... (10 Replies)
Discussion started by: Krishanu Saha
10 Replies

3. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

4. Shell Programming and Scripting

Escaping special characters

I'm attempting a little hack to get grep to highlight (change foreground color to red) a found string. Assuming a target file "test" consisting of the word "albert": My executable "algrep" consists of this: grep $1 $2 | sed "s/$1/\\\033 And when run: algrep al test Produces this:... (2 Replies)
Discussion started by: tiggyboo
2 Replies

5. Shell Programming and Scripting

Remove lines with non-chinese characters from xml file

Hi there, I'm looking for a way to remove all lines that don't contain chinese characters from an xml file. Example: http://pastebin.com/8KzSbCKe The result should be like this: http://pastebin.com/ZywXsNhx Only lines that don't contain chinese characters should be deleted. If theres a mix of... (3 Replies)
Discussion started by: g4rb4g3
3 Replies

6. UNIX for Dummies Questions & Answers

XML file shows Junk Characters in UNIX

Hello sir, I have generated XML file from VS 2005. It works well in windows but it shows some junk characters in unix. Can any help me with this problem. Thank you in advance. Hema (6 Replies)
Discussion started by: hemavenkatesh
6 Replies

7. UNIX for Dummies Questions & Answers

Escaping non-readable characters using grep, sed or awk

I'm trying to parse out DNS logs from dozens of different domain controllers over a large period of time. The logs are rolled up into individual text files by size, which may contain only a portion of a day's activity or several day's worth (depending on amount of activity). I'm splitting them by... (4 Replies)
Discussion started by: seanwpaul
4 Replies

8. Shell Programming and Scripting

Escaping Special characters

I want to append the following line to /var/spool/cron/root: */7 * * * * /root/'Linux CPU (EDF).sh' > /dev/null 2>&1 How to accomplish this using echo? ---------- Post updated at 04:09 PM ---------- Previous update was at 04:07 PM ---------- "Linux CPU (EDF)" is actually stored in a... (11 Replies)
Discussion started by: proactiveaditya
11 Replies

9. Shell Programming and Scripting

Escaping Special Characters-Help

Hi All, I am having a trouble in passing special characters to a script. As I am new to bash script I dont know how to go and solve this. mypwd=(a+sdfg!h# if i pass $mypwd to a bash script, it is not accepting "(,!,+ etc". It would be a great help if some one can help to escape these... (3 Replies)
Discussion started by: Tuxidow
3 Replies

10. Shell Programming and Scripting

escaping special characters in file name...

dear, I would like to rename files in a dir to another format, so I write a bash shell script to handle it. But my problem now is how to handle files having special characters like spaces, (, ): "a b c (d).doc" It seems that I need to escape those characters before applying the "mv" command.... (1 Reply)
Discussion started by: lau0001
1 Replies
Login or Register to Ask a Question