Removing special characters from multiple csv files using a batch file

I want to delete all special characters in my csv file using a batch file. My csv file contains only one column only for keywords to be entered in google

For example 1.Ecommerce 2.dentist Melbourne cbd? 3.dentists Melbourne% 4. Best dentist in Melbourne!

Sometimes I can have Aracbic / Chinese Characters etc.

Here, when I add these files to the GoogleAdwords-Keyword Planner, it shows me an error; when I ignore the error, I am mistaken. hits for the keyword and avoid mistakes. I need to remove all special characters from my csv file.

I have hundreds of csv files and you want to save the updated (without special characters) file to an existing file.

I tried

@echo off set source_folder=C:\Users\Username\Documents\iMacros\Datasources\a set target_folder=C:\Users\Username\Documents\iMacros\Datasources\keyfords-csv-file if not exist %target_folder% mkdir %target_folder% for /f %%A in ('dir /b %source_folder%\*.csv') do ( for /f "skip=1 tokens=1,2* delims=," %%B in (%source_folder%\%%A) do ( echo %%B>>%target_folder%\%%A ) ) timeout /t 20 

But the deletion of all the entries from the csv file has ended.

Anyway, I can either

1. Select only standard characters, which will be from AZ, az, and 0-9.

2.Or Delete the whole line where I can put special characters on this line. like string1 = "% @ # $ ^ & ?! * <>"

3. In any case, I can mention in the csv file to accept only standard English characters. Is there a way to achieve this using a batch file or any framework?

thanks

+8
excel csv batch-file
source share
2 answers

I think this is a lot cleaner in Powershell.

 $sourceFolder = "C:\Users\Username\Documents\iMacros\Datasources\a" $targetFolder = "C:\Users\Username\Documents\iMacros\Datasources\keyfords-csv-file" MkDir $targetFolder -ErrorAction Ignore $fileList = Dir $sourceFolder -Filter *.csv ForEach($file in $fileList) { $file | Get-Content | %{$_ -replace '[^\w\s,\"\.]',''} | Set-Content -Path "$targetFolder\$file" } 

I take each file from the source folder, get the contents, replace any character that is not needed, and save it in another file. I use a small regular expression right in the middle of '[^\w\s,\"\.]' With the replace command. Carrot ^ is an incompatible operator. So, everything that doesn't match the character of the word \w , space \s , coma , , double quotation marks \" or period \.

Someone might find the best regex for your needs, but I think you get the idea.

0
source share

Technically, you can have a series:

 set variable=%variable:"=% set variable=%variable:(=% set variable=%variable:)=% set variable=%variable:&=% set variable=%variable:%=% 

And so on. I know that it would be a shame to write all the special characters.

Seeing that there will be fewer letters in the alphabet than "special characters", you can find findstr by the name of the file / folder, if the letter from az is found true, write and go to the next character.

_Arescet

0
source share

All Articles