<http://www.netikka.net/tsneti/info/tscmd081.htm>
Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Fri 23-Apr-2010 20:15:31

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



81} Is there a script to capitalize all the words in a text file?

 Q: "I need a batch file that will change the first letter in every word in a text file to upper case."

 A: Using sed
  @echo off & setlocal enableextensions
  if not defined mytemp set mytemp=%temp%
  set sedcmd="%mytemp%\sedcmd.tmp"
  >  %sedcmd% echo s/ a/ A/g
  >> %sedcmd% echo s/ b/ B/g
  >> %sedcmd% echo s/ c/ C/g
  >> %sedcmd% echo s/ d/ D/g
  >> %sedcmd% echo s/ e/ E/g
  >> %sedcmd% echo s/ f/ F/g
  >> %sedcmd% echo s/ g/ G/g
  >> %sedcmd% echo s/ h/ H/g
  >> %sedcmd% echo s/ i/ I/g
  >> %sedcmd% echo s/ j/ J/g
  >> %sedcmd% echo s/ k/ K/g
  >> %sedcmd% echo s/ l/ L/g
  >> %sedcmd% echo s/ m/ M/g
  >> %sedcmd% echo s/ n/ N/g
  >> %sedcmd% echo s/ o/ O/g
  >> %sedcmd% echo s/ p/ P/g
  >> %sedcmd% echo s/ q/ Q/g
  >> %sedcmd% echo s/ r/ R/g
  >> %sedcmd% echo s/ s/ S/g
  >> %sedcmd% echo s/ t/ T/g
  >> %sedcmd% echo s/ u/ U/g
  >> %sedcmd% echo s/ v/ V/g
  >> %sedcmd% echo s/ w/ W/g
  >> %sedcmd% echo s/ x/ X/g
  >> %sedcmd% echo s/ y/ Y/g
  >> %sedcmd% echo s/ z/ Z/g
  rem
  >> %sedcmd% echo s/^^a/A/g
  >> %sedcmd% echo s/^^b/B/g
  >> %sedcmd% echo s/^^c/C/g
  >> %sedcmd% echo s/^^d/D/g
  >> %sedcmd% echo s/^^e/E/g
  >> %sedcmd% echo s/^^f/F/g
  >> %sedcmd% echo s/^^g/G/g
  >> %sedcmd% echo s/^^h/H/g
  >> %sedcmd% echo s/^^i/I/g
  >> %sedcmd% echo s/^^j/J/g
  >> %sedcmd% echo s/^^k/K/g
  >> %sedcmd% echo s/^^l/L/g
  >> %sedcmd% echo s/^^m/M/g
  >> %sedcmd% echo s/^^n/N/g
  >> %sedcmd% echo s/^^o/O/g
  >> %sedcmd% echo s/^^p/P/g
  >> %sedcmd% echo s/^^q/Q/g
  >> %sedcmd% echo s/^^r/R/g
  >> %sedcmd% echo s/^^s/S/g
  >> %sedcmd% echo s/^^t/T/g
  >> %sedcmd% echo s/^^u/U/g
  >> %sedcmd% echo s/^^v/V/g
  >> %sedcmd% echo s/^^w/W/g
  >> %sedcmd% echo s/^^x/X/g
  >> %sedcmd% echo s/^^y/Y/g
  >> %sedcmd% echo s/^^z/Z/g
  rem
  sed -f%sedcmd% < "My test file.txt"
  for %%f in (%sedcmd%) do if exist del %%f
  endlocal & goto :EOF

Assume the following LFN-type test file: "My test file.txt"
  line 1
  line 2 &()[]{}^=;!'+,`~
  line 3 <>
 
  ö
  06
  line 7 Line "4" is blank, "5" and "6" are short!
  line 8
  line 9 &()[]{}^=;!'+,`~ ends it

The output will be
  C:\_D\TEST>cmdfaq
  Line 1
  Line 2 &()[]{}^=;!'+,`~
  Line 3 <>

  ö
  06
  Line 7 Line "4" Is Blank, "5" And "6" Are Short!
  Line 8
  Line 9 &()[]{}^=;!'+,`~ Ends It

What about foreign character sets? For example for the Finnish character set add
  >> %sedcmd% echo s/ å/ Å/g
  >> %sedcmd% echo s/ ä/ Ä/g
  >> %sedcmd% echo s/ ö/ Ö/g
  rem
  >> %sedcmd% echo s/^^å/Å/g
  >> %sedcmd% echo s/^^ä/Ä/g
  >> %sedcmd% echo s/^^ö/Ö/g

Of course, one could emulate the above with a pure script, to a degree, or with a Visual Basic Script (VBScript) aided command line script. However, the task is so much better suited for the specialized SED stream editor that the alternatives are left to the gentle reader as an exercise. If you are interested, take additional cues from item #39.

References/Comments: (If a Google message link fails try the links within the brackets.)
  Google Groups Jan 16 2005, 8:41 pm [M]
  Google Groups Jan 16 2005, 8:57 pm [M]
  Google Groups Jan 16 2005, 12:46 pm [M]