Thursday 15 March 2012

excel - Delete special characters from multiple csv files using batch file -



excel - Delete special characters from multiple csv files using batch file -

i want delete special characters in csv file using batch file. csv file has 1 column of keywords entered in google

for illustration 1.ecommerce 2.dentist melbourne cbd? 3.dentists melbourne % 4.best dentist in melbourne!

sometimes can have aracbic/chinese characters , on.

here when add together these files googleadwords-keyword planner, shows me error, on ignoring error wrong no. of hits keyword , avoid error need remove special characters csv file.

i have hundreds of csv files , want save updated(without special characters) file 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% /f %%a in ('dir /b %source_folder%\*.csv') ( /f "skip=1 tokens=1,2* delims=," %%b in (%source_folder%\%%a) ( echo %%b>>%target_folder%\%%a ) ) timeout /t 20

but ended deleting records csv file.

is there anyway can either

1.accept standard characters a-z, a-z, , 0-9.

2.or delete string can set special characters in string. string1="?%!@#$^&*<>"

3.or there anyway can mention in csv file take standard english language characters there way accomplish using batch file or framework?

thanks

i think much 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 every file source folder, contents, replace character not wanted, , save file. utilize little regex right in middle '[^\w\s,\"\.]' replace command. carrot ^ not match operator. not match word character \w, space character \s, coma ,, double quote \", or period \.

someone may find improve regex needs, think idea.

excel batch-file csv

No comments:

Post a Comment