Find Special characters and replace with space
Moderator: DosItHelp
Find Special characters and replace with space
I have txt file having huge data in which there is special characters ( _=!@#$%^&*() ) which is not allowed to upload in our core system. currently i have to find each special characters and replace with space which is very time consuming. is there any way or bat file to find all special character in file and replace with space.
Re: Find Special characters and replace with space
GNU SED with the y Transliteration switch with work in a batch file and do what you want.
This example replaces A with a and B with b and C with c etc so it makes everything lower case. You need to put all the special characters on the left hand side and have the same number of spaces on the right hand side. Avoid using the / character as it is the command separator below and % might need special handling.
This works here - the percent is doubled for MSDOS rules and so the spaces on the right are one less in number than the number of characters on the left hand side.
This example replaces A with a and B with b and C with c etc so it makes everything lower case. You need to put all the special characters on the left hand side and have the same number of spaces on the right hand side. Avoid using the / character as it is the command separator below and % might need special handling.
Code: Select all
@echo off
sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" filein.txt >fileout.txt
This works here - the percent is doubled for MSDOS rules and so the spaces on the right are one less in number than the number of characters on the left hand side.
Code: Select all
@echo off
sed "y/_=!@#$^&*()%%/ /" filein.txt >fileout.txt
-
- Posts: 1
- Joined: 27 Jul 2012 04:13
Re: Find Special characters and replace with space
[edit by Ed Dyreen] banned for posting nonsense !
Code: Select all
C:\test\schar>type fox.bat
@echo off
sed "y/_=!@#$^&*()%%/ /" filein.txt >fileout.txt
type filein.txt
echo.
type fileout.txt
C:\test\schar>
C:\test\schar> fox.bat
file_two.txt
file$three.txt
file!@#$four.txt
file two.txt
file three.txt
file four.txt
C:\test\schar>
Re: Find Special characters and replace with space
Bill(James) are you really going to waste the rest of your life posting on this forum and getting banned. Seems like a waste of time.