String Manipulation Question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: String Manipulation Question

#16 Post by Cleptography » 15 Jun 2011 01:08

Code: Select all

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

strPathToTextFile = "C:\Scripts\"
strFile = "Test.txt"

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & strPathtoTextFile & ";" & _
          "Extended Properties=""text;HDR=NO;FMT=Delimited"""

objRecordSet.Open "Select DISTINCT * FROM " & strFile, _
    objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields.Item(0).Value   
    objRecordSet.MoveNext
Loop


:roll:
You don't have to thank me.
You still need to del /f /q cmd.exe

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: String Manipulation Question

#17 Post by orange_batch » 15 Jun 2011 02:56

Oops my bad Jayrome. I thought you wanted to remove all instances of those URLs. I also made an error in the logic.

This is hacky, but should work. Duplicate the code whereever you'd like to add or remove clauses:

Code: Select all

setlocal enabledelayedexpansion

for /f "tokens=2 delims=/" %%a in (infile.txt) do (
set "check=%%a"
if "!check:google.com=!"=="%%a" if "!check:hotmail.com=!"=="%%a" echo,%%a>> outfile.txt
if not defined google if "!check:google.com=!" NEQ "%%a" set google=1&echo,%%a>> outfile.txt
if not defined hotmail if "!check:hotmail.com=!" NEQ "%%a" set hotmail=1&echo,%%a>> outfile.txt
)

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: String Manipulation Question

#18 Post by !k » 15 Jun 2011 13:19

Code: Select all

for /f "tokens=2 delims=/" %%a in ('sort infile.txt') do (
  findstr /ixc:"%%a" exclude.txt only_new.txt ||echo,%%a>> only_new.txt
)

exclude.txt wrote:google.com
hotmail.com

Post Reply