I want to programmatically edit file content using windows command line (cmd.exe). In *nix there is sed for this tasks. Is there any usefull equivalent in windows?
Edit: I am looking for native command line solution.
You could install Cygwin (http://www.cygwin.com/) and use sed from there.
edlin or edit
plus there is Windows Services for Unix which comes with many unix tools for windows. http://technet.microsoft.com/en-us/interopmigration/bb380242.aspx
As far as I know nothing like sed is bundled with windows. However, sed is available for Windows in several different forms, including as part of Cygwin, if you want a full POSIX subsystem, or as a Win32 native executable if you want to run just sed on the command line.
Sed for Windows (GnuWin32 Project)
If it needs to be native to Windows then the only other thing I can suggest would be to use a scripting language supported by Windows without add-ons, such as VBScript.
You could try powershell. There are get-content and set-content commandlets build in that you could use.
I use Cygwin. I run into a lot of people that do not realize that if you put the Cygwin binaries on your PATH, you can use them from within the Windows Command shell. You do not have to run Cygwin's Bash.
You might also look into Windows Services for Unix available from Microsoft (but only on the Professional and above versions of Windows).
sed
(and its ilk) are contained within several packages of Unix commands.
EDIT after re-reading "native" several times...
Okay, you could build something sed-like in vbscript. Below is a gross, off-the-cuff stab at it. Your command line would look like cscript sed.vbs s/(oldpat)/(newpat)/ <inpfile.txt >outfile.txt
where oldpat and newpat are Microsoft vbscript regex patterns. Obviously i've only implemented the substitute command and assumed some things, but you could flesh it out to be smarter and understand more of the sed
command-line.
Dim pat, patparts, rxp, inp
pat = WScript.Arguments(0)
patparts = Split(pat,"/")
Set rxp = new RegExp
rxp.Global = True
rxp.Multiline = False
rxp.Pattern = patparts(1)
Do While Not WScript.StdIn.AtEndOfStream
inp = WScript.StdIn.ReadLine()
WScript.Echo rxp.Replace(inp, patparts(2))
Loop
simply said you are talking about Perl or Python or even Parrot. It will take just time to realize it ..
MKS Toolkit provides a good list of *nix style utilities.
www.mkssoftware.com/