hi ,
how can i replace tab/space with comma in a file(.csv file) by cmd commands?
error in tab/space with comma
Moderator: DosItHelp
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: error in tab/space with comma
pradeepcarya wrote:hi ,
how can i replace tab/space with comma in a file(.csv file) by cmd commands?
sure, you can download gawk for windows or
sed for windows, then
Code: Select all
C:\test> sed -i.bak -r "s/[ \t]+/,/g" file
C:\test> gawk -F"[ \t]+" "{$1=$1}1" OFS="," file
If you want to replace 1 space/tab with 1 comma, then remove the "+" sign
Last edited by ghostmachine4 on 18 Oct 2010 07:41, edited 1 time in total.
Re: error in tab/space with comma
via native CMD for TAB in file.csv:
P.S. replace spaces usually more complicated if dbl quotes used
Code: Select all
@(for /f "usebackq delims=" %%a in ("file.csv") do @(set "$a=%%a"
SetLocal EnableDelayedExpansion& echo !$a: =,!
EndLocal))>"%~dpn0.tmp"
@copy /y "%~dpn0.tmp" "file.csv"&& del /f "%~dpn0.tmp"
P.S. replace spaces usually more complicated if dbl quotes used
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: error in tab/space with comma
@amel27,
some tabs are 4 spaces, some are 8 , ie, its not fixed. The "tab" in your batch code is not the same as mine, therefore it doesn't work unless i change it in the code to the same number of tabs spaces. Any way to generalize it? like what i did for gawk using "\t" ?
also, what about spaces??
some tabs are 4 spaces, some are 8 , ie, its not fixed. The "tab" in your batch code is not the same as mine, therefore it doesn't work unless i change it in the code to the same number of tabs spaces. Any way to generalize it? like what i did for gawk using "\t" ?
also, what about spaces??