Friday, August 13, 2010

Doing Unix-type things on the Windows CMD prompt


I've playing around with the SVN command line recently, and the inability to use UNIX command-line tools like grep has been irritating. I've done some Googling for Windows equivalents to the basic Unix command line toolkit, and here's what I've found.



Unix Windows Notes
grep findstr Solid windows equivalent. You can do things like
svn info | findstr URL
to get the repository URL of your current working copy in SVN.
backquotes Use temp file with redirction
I wish windows allowed you to do this:
set url=`svn info | findstr URL`
You can't, but here's a nifty workaround:


svn info | findstr URL >url.tmp
set /p url=<url.tmp
You can further refine this with Windows' substring syntax
set /p url=%url:~5%
to strip out the "URL: " prefix. Now you placed your current working directory in a session variable.


Still looking for a way to do a UNIX tail, which shows the last 10 lines of a file.
Update: This comes with the Windows 2003 Resource Kit.

A hat tip to these blog posts:

UPDATE

Many a year later, I discovered Powershell, and my Unix envy subsided quite a bit.  PS pipes objects, not a measly text stream, from one command to another.  Try that, Unix!  Check out Scott Hanselman's walkthrough on DNR TV.

1 comment:

  1. Check out cygwin. This is supposed to supply unix utilities on Windows. (Haven't used it myself siince all my machines run Linux.)

    --Dad

    ReplyDelete