Convert Windows Metacharacters to Regular Text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert Windows Metacharacters to Regular Text
# 1  
Old 11-17-2010
Convert Windows Metacharacters to Regular Text

Hi, all.

I have a need to take a flat file FTP'd from Windows to Unix and convert it for loading into a MySQL database without manual intervention. However, some characters are "fancified" (e.g. the fancy Beginning and End double-quotes from Windows) that show up as codes using vi. I need to convert these to regular text in Unix. The codes are below:
<85>=...
<92>=‘
<93>=“
<94>=”

Example Text in WordPad
===================
(like a telephone, except “0” at top left

Same Text in Unix
===================
(like a telephone, except <93>0<94> at top left

[Note the difference in the double quotes.]

The codes show up in Putty vi as blue, so I know it recognizes they are metacharacters, but none of the methods I've tried in Unix (sed, awk) to search for metacharacters seems to find these.
# 2  
Old 11-17-2010
Here is a solution that uses bash arrays (easier to extend for other chars you find - like A9 for the copyright symbol).

Code:
#!/bin/bash
src=(85 92 93 94 A9)
dest=("..." \' \" \" "(c)")
for((i=0;i<${#src[@]};i++)) {
   SEDSTR="${SEDSTR};$(printf "s/%c/%s/" $(echo -e \\x${src[i]}) ${dest[i]})"
}
sed -i $SEDSTR myfile.txt


Last edited by Chubler_XL; 11-17-2010 at 06:12 PM.. Reason: Fix formatting
This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 11-17-2010
Quote:
Originally Posted by superdelic
Hi, all.

I have a need to take a flat file FTP'd from Windows to Unix and convert it for loading into a MySQL database without manual intervention. However, some characters are "fancified" (e.g. the fancy Beginning and End double-quotes from Windows) that show up as codes using vi. I need to convert these to regular text in Unix. The codes are below:
<85>=...
<92>=‘
<93>=“
<94>=”

Example Text in WordPad
===================
(like a telephone, except “0” at top left

Same Text in Unix
===================
(like a telephone, except <93>0<94> at top left

[Note the difference in the double quotes.]

The codes show up in Putty vi as blue, so I know it recognizes they are metacharacters, but none of the methods I've tried in Unix (sed, awk) to search for metacharacters seems to find these.
Why not provide some real samples and your expect O/P for easily understanding your question?
# 4  
Old 11-17-2010
rdcwayx, if you type "(like a telephone, except "0" at top ... left" into MS word and save as .txt you will have an example file. Here is and od -c of the file I use to test my solution:
Code:
$ od -c myfile.txt
0000000   (   l   i   k   e       a       t   e   l   e   p   h   o   n
0000020   e   ,       e   x   c   e   p   t     223   0 224       a   t
0000040       t   o   p     205       l   e   f   t  \r  \n

# 5  
Old 11-22-2010
MySQL Solid work. Thanks.

Quote:
Originally Posted by Chubler_XL
Here is a solution that uses bash arrays (easier to extend for other chars you find - like A9 for the copyright symbol).

Code:
#!/bin/bash
src=(85 92 93 94 A9)
dest=("..." \' \" \" "(c)")
for((i=0;i<${#src[@]};i++)) {
   SEDSTR="${SEDSTR};$(printf "s/%c/%s/" $(echo -e \\x${src[i]}) ${dest[i]})"
}
sed -i $SEDSTR myfile.txt

Totally what I needed to know. Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to convert utf-8 to WINDOWS-1251

Hello all i have utf-8 file that i try to convert to WINDOWS-1251 on linux without any success the file name is utf-8 when i try to do : file -bi test.txt it gives me : text/plain; charset=utf-8 when i try to convert the file i do : /usr/bin/iconv -f UTF-8 -t WINDOWS-1251 test.txt >... (1 Reply)
Discussion started by: umen
1 Replies

2. UNIX for Dummies Questions & Answers

Convert UNIX text file in Windows to recognize line breaks

Hi all, I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this? Or just reinsert thousands of line breaks again :eek: ? (2 Replies)
Discussion started by: frys_hp
2 Replies

3. Windows & DOS: Issues & Discussions

Convert UNIX text file in Windows to recognize line breaks

Hmmm I think I found the correct subforum to ask my question... I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this?... (1 Reply)
Discussion started by: frys_hp
1 Replies

4. Shell Programming and Scripting

Convert this Windows script so I can use it on Macbook

Hi guys, I am been banging my head for days on something that appears too simple to be so hard for me. I have this bash script which I used just fine on my windows PC. I took this file over to my Macbook and try to run it and it fails like no tomorrow. This is the contents of the file:... (3 Replies)
Discussion started by: richsark
3 Replies

5. Shell Programming and Scripting

help with organizing some non regular text

hey im trying to get the hex diffrences in two files ones called new and the other is named old i want it to phrase into my script, heres how i need the info: input='\x'94 #the new 1 byte hex change offset=00000000 #the 1st offset of the difference patch unset input offset input='\x'34... (5 Replies)
Discussion started by: lewisdenny
5 Replies

6. UNIX for Dummies Questions & Answers

Copying text from Windows to AIX - missing text?

Hi All, I'm hoping this is an easy question, but I'm having a weird problem trying to simply copy and paste text from MS Windows (XP) Notepad and then pasting into vi or vim in AIX. When I type "oslevel" I get "5.3.0.0". The problem is that once the text is pasted, there are sections of text... (2 Replies)
Discussion started by: PlainInverted
2 Replies

7. Shell Programming and Scripting

How can I get the matched text when using regular expression.

Hello: (exp) : match "exp",the matched text is stored in auto named arrays. How can I get the matched text ? What is the name of the auto named arrays on linux shell ? (4 Replies)
Discussion started by: 915086731
4 Replies

8. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

9. Solaris

convert windows OS as Solaris remotely

I have a Windows 2000 Terminal, which I want to convert into Solaris 10. I am connected to windows terminal remotely via iLO and then inserted the solaris DVD in my local drive. Now when I connect to Windows machine from 'RDP' - I can see local DVD in there - and IF I then reboot remote machine... (1 Reply)
Discussion started by: panchpan
1 Replies

10. UNIX for Dummies Questions & Answers

How do I convert unix text to to win text?

How do I convert unix text files into readable text for windows. Dave (1 Reply)
Discussion started by: nucca
1 Replies
Login or Register to Ask a Question