tags:

views:

66

answers:

2

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
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
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
no need to use type
ghostdog74
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
+1 in any case.....
ldigas
Yes, look at the for command at the command prompt. FOR %f IN (*.dat) DO ---the sed command---
kenny
+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
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
I don't mind downloading sed ...
ldigas
yes, using sed, specify `*.dat` .see edit. For the vbscript, you can use a DOS for loop to loop over your `*.dat` files.
ghostdog74