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 use cygwin?
From JeeBee -
You could install Cygwin (http://www.cygwin.com/) and use sed from there.
From robintw -
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
Joey : Both don't exist anymore on 64-bit versions of Windows.From Booji Boy -
You could look at GNU Tools, they provide (amongst other things) sed on windows.
From Linor -
UnxUtils provides sed for Win32, as does GNUWin32.
From Adam Hughes -
Cygwin works, but these utilities are also available. Just plop them on your drive, put the directory into your path, and you have many of your friendly unix utilities. Lighterweight IMHO that Cygwin (although that works just as well).
From Mark -
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.
From Jay -
You could try powershell. There are get-content and set-content commandlets build in that you could use.
Joey : Those are probably the two things in PowerShell that contribute least to what `sed` does ;-). The `-replace` operator is probably a better suggestion.From James Boother -
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).
From Brandon DuRette -
sed
(and its ilk) are contained within several packages of Unix commands.- Cygwin works but is gigantic.
- UnxUtils is much slimmer.
- GnuWin32 is another port that works.
- Another alternative is AT&T Research's UWIN system.
- MSYS from MinGw is yet another option.
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 thesed
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
Jakub Šturc : This is not exactly what I want however I beleave that the dependency upon VBS is the most lightest solution.Jakub Šturc : Anyway thank you a lot and all others for answers.Michael Paulukonis : GnuWin32 _is_ a native solution, if by native you mean designed to run in the "normal" windows environment (unlike CygWin). Give them a try, and you'll start expecting them to be on EVERY windows system you use. !!!Marko Dumic : Works for my case! Also, don't forget "//NoLogo" cscript option.From bill weaver -
This works on Vista Ultimate, not sure Pro.
sed -f commandfilename.cmd file1 > file2
-
simply said you are talking about Perl or Python or even Parrot. It will take just time to realize it ..
From YordanGeorgiev -
MKS Toolkit provides a good list of *nix style utilities.
www.mkssoftware.com/
From Raj More -
There is Super Sed an enhanced version of sed. For Windows this is a standalone .exe, intended for running from the command line.
From Rob Kam
0 comments:
Post a Comment