Any tip to replacing the special characters in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Any tip to replacing the special characters in a file
# 1  
Old 12-05-2018
Any tip to replacing the special characters in a file

Hi,

Please find attached a file that has special characters on it. It is a copy and paste from a Micro$oft file.

I don't want to use strings as it remove all the 'indentations' / 'formatting' so I am replacing them with space instead.
I am using the sed command below

Code:
sed "s/$(printf "\302")/ /g" special_chars.txt | sed "s/$(printf "\240")/ /g" | grep -v "^$" > 123.txt

Note that the sed command above has been specific to what special characters to replace. Is there any way that we can specify a range of special characters to search and replace so we don't need to always find out what is the special character/s to replace and change the sed command to suit?

Reply much appreciated. Thanks in advance.
# 2  
Old 12-05-2018
Do those characters really hurt?

We're seeing copious amounts of 'NO-BREAK SPACE' (U+00A0) Unicode Characters in your file, represented as multibyte UTF-8 0xC2 0xA0 (or \302 \240 in octal) char. sed definitely is NOT the right tool to cope with those in general (although it might with single occurrences). What encodings does your Microsoft host use? What your *nix node?


Some conversion might already be done during transfer by using the right ftp options / settings. Or use the dos2unix tool. Or iconv or recode commands.


For exactly above problem,

Code:
sed 's/\o302\o240/ /g' /tmp/special_chars.txt

might suffice...


EDIT: I vaguely remember from your recent post that you are using Solaris (you don't mention it here). Not sure if any of above is available, then. YMMV.

Last edited by RudiC; 12-06-2018 at 07:12 AM.. Reason: typos
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replacing string/special characters using a 'conversion' table

Hi, Does anyone know if there is a script or program available out there that uses a conversion table to replace special characters from a file? I am trying to remove some special characters from a file but there are several unprintable/control characters that some I need to remove but some I... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. UNIX for Dummies Questions & Answers

Replacing valuses containig space and special characters

**Extremely sorry for the typos in heading Old:CAST ('${DEFAULT_HIGH_DATE}' AS DATE FORMAT 'YYYY-MM-DD') New :CAST(CAST('${G_DEFAULT_HIGH_DATE}' AS DATE FORMAT 'MM-DD-YYYY') as DATE FORMAT 'YYYY-MM-DD') Need to change old format as new format cat file1 CAST ('${DEFAULT_HIGH_DATE}' AS... (1 Reply)
Discussion started by: 100bees
1 Replies

3. Shell Programming and Scripting

File containing special characters

Hello All, I am facing challenges in order to transfer a file from windows to unix box,the file contains a special character '×' ,now when I am transferring the file from windows to unix that special character converted to something else like 'Ã' ,another thing I have noticed that the hardware is... (1 Reply)
Discussion started by: prarat
1 Replies

4. Shell Programming and Scripting

Need help in replacing special characters

I am writing a ksh script. I need to replace a set of characters in an xml file. FROM="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÛÚÜÝßàáâãäåçèéêëìíîïðñòóôõö¿¶ø®"; TO="AAAAAAACEEEEIIIIDNOOOOOOUUUUYSaaaaaaceeeeiiiionooooo N R" I have used the code- sed 's/$FROM/$TO/g'<abc.xml But its not working. Can anyone tell me the code to do this? (3 Replies)
Discussion started by: saga20
3 Replies

5. Shell Programming and Scripting

Replacing string with special characters in shell

Hi, I am trying to replace a string in shell but it is not working correctly. @xcom.file@ needs to be replaced with tb137 Plz help.Thx. Please use and tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks. (4 Replies)
Discussion started by: manish72
4 Replies

6. Shell Programming and Scripting

Renaming a file and replacing the special character in the name with date

HI all, How can i rename some files and replace the special character in the name with todays date ex: Name#file1.txt Name#file2.txt to be renamed as Name.20091119.file1.txt Name.20091119.file2.txt (11 Replies)
Discussion started by: abhinav192
11 Replies

7. Shell Programming and Scripting

help on sed replacing special characters

Hello, I have a file with many lines with below format: \abc\\1234 jkl\\567 def\\345 \pqr\\567 \xyz\\234 Here, i need to do 2 things. 1. replace \\ with \ 2. remove starting \ so output to be as below: (11 Replies)
Discussion started by: prvnrk
11 Replies

8. Shell Programming and Scripting

Replacing French special characters

Hi, I have tonnes of .txt files that are written in French. I need to replace the French special characters, however, with English equivalents (e.g. é -> e and ç -> c). I have tried this --- #!/bin/bash # Convert French characters to normal characters # Treat each of the files exec... (4 Replies)
Discussion started by: BlueberryPickle
4 Replies

9. UNIX for Dummies Questions & Answers

how to see special characters in a file using vi

Hi, I have a file which has special characters. I can't see them when I "vi" the file. But I am sure there are some special un seen characters. How can I see them? Please help. Thx (6 Replies)
Discussion started by: jingi1234
6 Replies

10. UNIX for Dummies Questions & Answers

search special characters in a file

Hello I am new to shell scripting and can anyone tell me how to check if there are any special characters in a file. Can i use grep ? thanks susie (2 Replies)
Discussion started by: cramya80
2 Replies
Login or Register to Ask a Question