I want to delete all the special characters in my csv file using a batch file. My csv file has one column of only keywords to be entered in google
我想使用批处理文件删除csv文件中的所有特殊字符。我的csv文件中只有一列关键字要在谷歌中输入
For example 1.Ecommerce 2.dentist Melbourne cbd? 3.dentists Melbourne % 4.best dentist in Melbourne!
例如1。电子商务2.牙医墨尔本cbd吗?3.牙医墨尔本% 4。最好的牙医在墨尔本!
Sometimes I can have Aracbic/Chinese Characters as well and so on.
有时我也可以有圆珠笔/汉字等。
Here When I add these files to GoogleAdwords-Keyword Planner, it shows me an error, on ignoring error i get wrong no. of hits for keyword and to avoid error i need to remove all the special characters from my csv file.
在这里,当我将这些文件添加到google lead -关键字规划器时,它显示了一个错误,在忽略错误时,我出错了。为了避免错误,我需要从csv文件中删除所有特殊字符。
I have Hundreds of csv files and want to save the updated(Without special characters) file to the existing file.
我有数百个csv文件,希望将更新后的(没有特殊字符)文件保存到现有文件中。
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 ended up Deleting all the records from csv file.
但是最终删除了csv文件中的所有记录。
Is there anyway by which i can either
无论如何,我都能做到吗
1.Accept only Standard Characters which would be from A-Z, a-z, and 0-9.
1。只接受来自A-Z、A-Z和0-9的标准字符。
2.Or Delete all the string where I can put special characters in that string. Like string1="?%!@#$^&*<>"
2。或者删除所有字符串,我可以把特殊字符放在那个字符串中。像string1 = " ? % ! @ # $ ^ & * < > "
3.Or is there anyway by which i can mention in csv file to accept only Standard English Characters Is there any way to achieve this using a batch file or any framework?
3所示。或者我在csv文件中提到只接受标准英文字符有什么方法可以通过批处理文件或任何框架实现这一点吗?
Thanks
谢谢
2 个解决方案
#1
0
I think this is much cleaner in Powershell.
我认为这在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 from the source folder, get the contents, replace any character that is not wanted, and save it to another file. I use a little regex right in the middle '[^\w\s,\"\.]'
with the replace command. The carrot ^
is a not match operator. So anything that does not match a word character \w
, space character \s
, a coma ,
, double quote \"
, or a period \.
我从源文件夹中取出每个文件,获取内容,替换任何不需要的字符,并将其保存到另一个文件中。我使用一个正则表达式在中间的[^ \ w \ s \ \”。用替换命令。胡萝卜^是一个不匹配算子。任何不匹配的字串,空格字串,昏迷,双引号,或句号。
Someone may find a better regex for your needs, but I think you get the idea.
也许有人能找到更好的regex来满足你的需要,但我想你已经明白了。
#2
0
Technically you could have a series of:
技术上,你可以有一系列:
set variable=%variable:"=%
set variable=%variable:(=%
set variable=%variable:)=%
set variable=%variable:&=%
set variable=%variable:%=%
And so on. I know this would be an annoyance to write all the special characters..
等等。我知道写这么多特别的字会让人讨厌。
Seeing there would be less letters in the alphabet than "special characters" a findstr could be done on the file/folder name, if a letter from a-z is found true, write and move to the next character.
如果发现a-z的字母为真,那么就编写并移动到下一个字符。
_Arescet
_Arescet
#1
0
I think this is much cleaner in Powershell.
我认为这在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 from the source folder, get the contents, replace any character that is not wanted, and save it to another file. I use a little regex right in the middle '[^\w\s,\"\.]'
with the replace command. The carrot ^
is a not match operator. So anything that does not match a word character \w
, space character \s
, a coma ,
, double quote \"
, or a period \.
我从源文件夹中取出每个文件,获取内容,替换任何不需要的字符,并将其保存到另一个文件中。我使用一个正则表达式在中间的[^ \ w \ s \ \”。用替换命令。胡萝卜^是一个不匹配算子。任何不匹配的字串,空格字串,昏迷,双引号,或句号。
Someone may find a better regex for your needs, but I think you get the idea.
也许有人能找到更好的regex来满足你的需要,但我想你已经明白了。
#2
0
Technically you could have a series of:
技术上,你可以有一系列:
set variable=%variable:"=%
set variable=%variable:(=%
set variable=%variable:)=%
set variable=%variable:&=%
set variable=%variable:%=%
And so on. I know this would be an annoyance to write all the special characters..
等等。我知道写这么多特别的字会让人讨厌。
Seeing there would be less letters in the alphabet than "special characters" a findstr could be done on the file/folder name, if a letter from a-z is found true, write and move to the next character.
如果发现a-z的字母为真,那么就编写并移动到下一个字符。
_Arescet
_Arescet