Search and Replace small letter string to cap

January 21, 2011 at 03:21:45
Specs: Windows XP
I have a text file whuch contain strings of both capital and small letters. I need to write a BAT file to replace all the small letters to capital and save in the same text file.

See More: Search and Replace small letter string to cap

Report •


#1
January 21, 2011 at 05:03:02
::===========================================
@echo off & setLocal EnableDELAYedeXpansion
call :make-UPP
upper.com < myfile > #.d && move /y #.d myfile && del upper.com
goto :eof

:make-UPP
@echo off > #.d
>> #.d echo E0100 E9 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E01A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E01B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E01C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E01D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E01E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E01F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
>> #.d echo E0200 00 00 00 00 80 3E 80 00 00 74 1B A0 80 00 32 E4 
>> #.d echo E0210 8B F0 C6 84 81 00 00 8D 16 82 00 B0 00 B4 3D CD 
>> #.d echo E0220 21 72 3A A3 03 01 8B 1E 03 01 B9 FF 00 8D 16 05 
>> #.d echo E0230 01 B4 3F CD 21 72 26 3D 00 00 74 21 50 8B C8 8D 
>> #.d echo E0240 36 05 01 8B FE AC 3C 61 7C 06 3C 7A 7F 02 2C 20 
>> #.d echo E0250 AA E2 F2 59 BB 01 00 B4 40 CD 21 EB C9 CD 20 1A 
>> #.d echo E0260 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 
>> #.d echo E0270 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 
>> #.d echo N UPPER.COM
>> #.d echo RCX
>> #.d echo 0180
>> #.d echo W
>> #.d echo Q

debug < #.d > nul
goto :eof


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
January 22, 2011 at 05:10:07
@M2, are you serious?? you are seriously asking OP to maintain that obfuscated piece of code that nobody would understand except you?

@OP, use a good file processing tool, you can download sed for windows or coreutils for windows. then try this

tr a-z A-Z < file

or

sed "y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/" file

GNU win32 packages | Gawk


Report •

#3
January 22, 2011 at 05:13:54
Hi goshtdog,

I dunno about 'maintain' but if you just paste it into a BAT, it should do the deed.


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
January 22, 2011 at 05:51:05
"maintain" means the code should be readable and understandable to anyone who is taking care of it. IF a batch method is really a must, its still "maintainable" to code something like this

for loop to go through each character do (
   if character == "a" (
       echo "A" or set something to "A"
   )else if character == "b" (
       echo "B" or set something to "B"
   )
   ...
   else if character == "z" (
          .........
   )
)

for a native solution, changing case is easily done with vbscript ( which there is no excuse not to get acquainted with it in this current computing age and the fact that its installed by default already).

GNU win32 packages | Gawk


Report •

#5
January 22, 2011 at 06:39:54
A "pure batch" to upper:

@echo off
setlocal disabledelayedexpansion

set inputfiLe="thefile.txt"
set outputfile="newfile.txt"



for /f "delims=" %%a in (' find /n /v "" ^< %inputfile% ') do (
    set line=%%a
    SetLocal EnableDelayedExpansion
    set line=!line:*]=!
    if defined line (
        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!
        )
        >> !outputfile! echo.!line!
    ) else >> !outputfile! echo.
    endlocal
)
pause

Edit

To save to the "same" file add:

move %outputfile% %inputfile%

Just before pause.


Report •

#6
January 22, 2011 at 07:01:30
>> A "pure batch" to upper
I wouldn't say its "pure", since you are using external find command.but nevertheless, better than "assembly"

Also, there's no need to redirect input file , since find can take in an input file and save on escaping the < sign

for /f "delims=" %%a in ('c:\windows\system32\find /n /v ""  %inputfile% ')

GNU win32 packages | Gawk


Report •

#7
January 22, 2011 at 07:18:06
True, find is external but it's still hard to say it's not part of batch, after all it was available before "for /f", "delayed expansion" and "var:str=rep".

Also, there's no need to redirect input file , since find can take in an input file and save on escaping the < sign

Not unless you want:

<empty line>
---------- somefile.txt

In the output.

The find is there for two reasons, lines that begin with ";" (eol can be changed but not turned off) and for empty lines(which "for /f" ignores).


Edit: "skip=2 delims=" could also avoid redirecting and the find output....


Report •

#8
January 22, 2011 at 08:25:47
>>True, find is external but it's still hard to say it's not part of batch,
I did not say its not part of batch. To me, if someone says "pure batch", i take it to mean only those from cmd.exe , eg for loop, if/else and any others that are internal to cmd.exe, and no external tools/programs. That said, is there a reason why you don't use "type file" instead of "find ... file" ??, since "type" is internal. If you have used that, then yes, your code can be considered "pure".

GNU win32 packages | Gawk


Report •

#9
January 22, 2011 at 18:19:18
Fair enough, I'm not going to argue...

That said, is there a reason why you don't use "type file" instead of "find ... file" ??, since "type" is internal. If you have used that, then yes, your code can be considered "pure".


I needed the "/n" switch for blank lines and lines that start with semi colons because it inserts"[<linenum>]" to the front of each line.



Report •

#10
January 24, 2011 at 00:54:57
Thank you Mechanix2Go, ghostdog and Judago for the response and discussion over here. I never expected a quick reply like this. Thank you once again. I could manage to customize Judago's code to serve my need.

Report •


Ask Question