The title pretty much says it all. What would be the easiest way to replace commas in all files it can find in the current directory with dots? (preferably, without installing some extra tools, but I'll settle for something small .... cygwin's not small :)
+3
A:
Get a copy of sed for windows which is perfect for these tasks and just use the 's' for substitute.
UPDATE: I just tested the following
type filename | sed -e "s/\,/\./" > outfilename
kenny
2010-04-04 14:15:42
Could you tell perhaps what is it exactly that I'd have to do after I install it ? I'm running short on time, and don't have the "luxury" of digging into the man files.
ldigas
2010-04-04 14:32:47
I provided a link that has sed.exe in the zip file and a link to writing substitute commands. Something like 'sed 's/\,/\\.r/' filename > outfilename' should do it. The \ is to escape the characters, not sure if you'll need to escape the comma.
kenny
2010-04-04 14:47:31
no need to use type
ghostdog74
2010-04-04 15:13:34
yes, but this will replace them one by one (i need to type every file name) ... is there a way to make it work on all, for example, *.dat ?
ldigas
2010-04-04 15:20:12
+1 in any case.....
ldigas
2010-04-04 15:22:02
Yes, look at the for command at the command prompt. FOR %f IN (*.dat) DO ---the sed command---
kenny
2010-04-05 11:19:43
+2
A:
download sed for windows from GNU. (The link kenny gave is dated ). Its just one executable and its small (and you can bring around on your thumb drive )
c:\test> sed -i.bak "s/,/./g" *.dat
-i.bak
just tell sed to backup your original file , and the "g" modifier says to replace all commas.
If you don't want to download stuff, you can use vbscript
Set objFS=CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfLine
strLine = objFile.ReadLine
strLine = Replace(strline,",",".")
WScript.Echo strLine
Loop
objFile.Close
save as myscript.vbs and on the command line
c:\test> cscript //nologo myscript.vbs > newfile
ghostdog74
2010-04-04 15:16:04
Is there a way to make it work on all, for example, files *.dat instead of typing them one by one (I have about 200 of them)?
ldigas
2010-04-04 15:21:20
yes, using sed, specify `*.dat` .see edit. For the vbscript, you can use a DOS for loop to loop over your `*.dat` files.
ghostdog74
2010-04-04 23:35:18