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 thought on “Gnu For Windows

Comments are closed.