1.

Solve : change uppercase to lowercase?

Answer»

I have an html file that's quiet large, nearly 7000 lines.

It has thousands of URLs pointing to a WEBSERVER that (for a strange reason) doesn't support UPPERCASE URLs...

How do I change all the tags www.SOMESITE.com/DIR/FILE1.HTM>, www.SOMESITE.com/DIR/FILE2.HTM> and so on to URLs with only lowercase letters?

I've tried using regex in Notepad++ but can't find the appropriate expression...so I thought that a batch file might do?Any Linux or Unix user will tell you that it's not a "strange reason". Windows is case-insensitive. But the Internet is not BUILT on Windows.

see if this works

Code: [Select]rem echo off
setlocal enabledelayedexpansion
if exist Output.html del Output.html
for /f "delims=" %%L in (Input.html) do (
    set line=%%L
 
    set line=!line:A=a!
    set line=!line:B=b!
set line=!line:C=c!
set line=!line:D=d!
set line=!line:E=e!
set line=!line:F=f!
set line=!line:G=g!
set line=!line:H=h!
set line=!line:I=i!
set line=!line:J=j!
set line=!line:K=k!
set line=!line:L=l!
set line=!line:M=m!
set line=!line:N=n!
set line=!line:O=o!
set line=!line:P=p!
set line=!line:Q=q!
set line=!line:R=r!
set line=!line:S=s!
set line=!line:T=t!
set line=!line:U=u!
set line=!line:V=v!
set line=!line:W=w!
set line=!line:X=x!
set line=!line:Y=y!
set line=!line:Z=z!
   
echo [I] %%L
echo [O] !line!
    echo.!line! >> Output.html
    )
   
    Quote from: swede on December 02, 2009, 07:36:58 AM

so I thought that a batch file might do?
batch is never the first choice for an appropriate tool to do parsing of files. Tools like Perl,Python, gawk,sed are designed to parse files easily, among other things they can do. If you can, try to use them, otherwise, if you really want to stick to "batch", you can use vbscript, which natively installed on your system.

Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile = objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
ISFOUND = InStr(strLine,"HREF")
If IsFound > 0 Then
s=Mid(strLine,IsFound + Len("HREF=" & """"))
whereIsQuote = InStr(s,""""& ">")
strUrl = LCase(Mid(s,1,whereIsQuote))
WScript.Echo Mid(strLine,1, IsFound-1) & "HREF=" & """" & strUrl & Mid(s,whereIsQuote+1)
Else
WScript.Echo strLine
End If
Loop

output
Code: [Select]C:\test>more file
<html>

lskhdfl
dsf
<p> .,,,,, </P>
dfj
some tages ... <A HREF="www.SOMESITE.com/DIR/FILE1.HTM"> somesite </A>

aslfjf asjldf <B> sdfhl </B> <A HREF="www.SOMESITE.com/DIR/FILE2.HTM"> some OTHER site </A> ...asdf

</html>

C:\test>cscript /nologo test.vbs file
<html>

lskhdfl
dsf
<p> .,,,,, </P>
dfj
some tages ... <A HREF="www.somesite.com/dir/file1.htm"> somesite </A>

aslfjf asjldf <B> sdfhl </B> <A HREF="www.somesite.com/dir/file2.htm"> some OTHER site </A> ...asdf

</html>
Quote from: Salmon Trout on December 02, 2009, 10:23:52 AM
see if this works
it works, but it will change all other caps that needs to be caps. Quote from: gh0std0g74 on December 02, 2009, 06:02:15 PM
it works, but it will change all other caps that needs to be caps.
What NEEDS to be capitalized? Quote from: Helpmeh on December 02, 2009, 06:13:01 PM
What NEEDS to be capitalized?
actual words that should appear capitalized when you view the page. EG, Every first words of paragraphs of text, or every word after a full stop etc. OP just wants to change the URL to small caps, not the whole html page. Quote from: gh0std0g74 on December 02, 2009, 06:48:41 PM
actual words that should appear capitalized when you view the page. Eg, Every first words of paragraphs of text, or every word after a full stop etc. OP just wants to change the URL to small caps, not the whole html page.
Wow...I feel kinda stupid, so I shal rephrase, is there any CODE that requires case?Can we ask the OP how did he get a list of URLs that were in upper case. Or who put upper case in links in a web page. You would thin that the error would have been corrected and the time of data entry.
But sometimes a URL may have some part that has to be upper case. Not everybody puts the names of things in lower case.Safari auto-decapitalizes btw.  Quote from: Helpmeh on December 02, 2009, 07:14:14 PM
Wow...I feel kinda stupid, so I shal rephrase, is there any CODE that requires case?
don't understand. What "CODE" are you taking about? you should give examples to your query as much as possible Quote from: gh0std0g74 on December 02, 2009, 06:02:15 PM
it works, but it will change all other caps that needs to be caps.

I know, and I was thinking up a VBS script that was broadly ALONG the lines of your contribution.



Discussion

No Comment Found