Windows batch file read text file and convert all to uppercase

喜夏-厌秋 提交于 2019-12-18 07:02:40

问题


I just simply want to replace all the text in the text file convert to uppercase.

For example of abc.txt

[Before conversion] First Name, Last Name, Full Name Brad, Pitt, Brad Pitt

[After conversion] FIRST NAME, LAST NAME, FULL NAME BRAD, PITT, BRAD PITT

Is that possible??


回答1:


The Batch file below do what you want, but if the file to convert is large this method is slow...

@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%a in (%1) do (
   set "line=%%a"
   for %%b in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "line=!line:%%b=%%b!"
   )
   echo !line!
)

To use this program, place the name of the file in the first parameter. For example, if this Batch file is called TOUPPER.BAT:

toupper abc.txt

Note that this program eliminate empty lines and any exclamation mark existent in the file. These limitations may be fixed if needed, but the program becomes even slower...

Antonio



来源:https://stackoverflow.com/questions/15648560/windows-batch-file-read-text-file-and-convert-all-to-uppercase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!