Gnu For Windows

We here at Deft Flux have always preferred Unix style operating systems and commands to Microsoft.  The problem was that our clients always use Microsoft operating systems and until recently, it was always too much of a hassle to get gnu utilities up and running on a Microsoft workstation, especially when you’re moving to a new one every few months.  Well, since the good folks at gnu started compiling programs for windows and providing installation programs (to cover dependancies), we decided every workstation needs gnu utilities.  First, we install gvim because it is the best text editor ever written.  Then we install grep, core utilities, and finally sed.  Thus we have assembled, on a Microsoft workstation, a group of what are arguably the most useful programs ever written, pound for pound.

Now when you are using gvim, you are editing files faster than ever.  But when you are using grep and sed and so on, you get a request to remove commas from the names of 20,000 files and you say “with pleasure.”dir /b | grep , | \
sed -e "s/^.*/\d034&\d034 /;h" -e "s/,/_/;x" \
-e "s/^.*/mv &/;G" -e "s/\n//"

  • We used dir at the beginning because it runs faster than ls in a Windows directory with 20,000 files.  One could just as easily use ls.
  • Even though we could have done the same thing with sed, we used grep just to take away one sed command.
  • We broke the sed commands into pieces because we were having problems with how Windows was passing arguments to sed.  This also makes the line [slightly] more readable.
  • The sed edits operate on this wise:
    • Add quotation marks to the beginning and the end of the file name.
    • Save the resulting string in a buffer (clipboard).
    • Replace commas in the file name with underscores.
    • Exchange the fixed file name with the buffer.  Now we’re working with the original file name.
    • Add the mv command before the original file name.
    • Paste the fixed filename after the mv and original file name.

Redirect this output to a file and you have a script to remove all of those pesky commas.  Sweet?  We think so.

1 Comment

  1. GNU tools for Windows is nice, but once you get that far, you may as well go the distance and install Cygwin. Use real bash, openssh and even an X server for running GUI software on remote computers (great for installing Oracle on a server without physical access). Most standard Linux utilities are available for Cygwin, and its installation size is not terrifically large, especially if you only want to run a few simple utilities.

    http://www.cygwin.org/cygwin/

Comments are closed.

© 2019 Deft Flux

Theme by Anders NorenUp ↑