String Manipulation Question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Jayrome
Posts: 7
Joined: 13 Jun 2011 21:44
Location: Australia

String Manipulation Question

#1 Post by Jayrome » 13 Jun 2011 22:02

I've been searching a while and not found anything quite related to what I want to achieve. Basically I have a batch file which runs a program to search all Internet Explorer history and outputs it to a text file, at the moment it looks messy like this but with hundreds of entries

URL : http://www.afl.com.au/bphf/header/adh.html

Is there a way I can run a command to do a string manipulation which will output only the http://"www.afl.com.au" or "www.google.com" for example instead of the full URL for some of them which I don't need? I read about extracting characters from strings but not sure how to do it in this situation or whether it can be done.

Thanks!

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

Re: String Manipulation Question

#2 Post by !k » 14 Jun 2011 09:02

Code: Select all

for /f "tokens=2 delims=/" %%a in (infile.txt) do echo,%%a>> outfile.txt

Jayrome
Posts: 7
Joined: 13 Jun 2011 21:44
Location: Australia

Re: String Manipulation Question

#3 Post by Jayrome » 14 Jun 2011 20:15

That worked great thank you! :D

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

Re: String Manipulation Question

#4 Post by Cleptography » 14 Jun 2011 20:26

Or you could go to you sytem32 dir find cmd.exe right click and scroll down to delete. Oh you would first have to delete it from the cache, and make sure to stop service.exe then you can delete cmd.exe.
Hope this helps.

Jayrome
Posts: 7
Joined: 13 Jun 2011 21:44
Location: Australia

Re: String Manipulation Question

#5 Post by Jayrome » 14 Jun 2011 20:30

Are you trying to be a smart arse ... I'm not trying to delete cmd.exe that's completely unrelated to what my enquiry was.

!K - Thanks again for the code it worked magic, another question, i'm trying to remove duplicates as google.com or hotmail.com etc comes up in the output 3-4 times, is there a delete command to remove duplicates?

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

Re: String Manipulation Question

#6 Post by Cleptography » 14 Jun 2011 20:57

Jayrome wrote:Are you trying to be a smart arse ... I'm not trying to delete cmd.exe that's completely unrelated to what my enquiry was.

!K - Thanks again for the code it worked magic, another question, i'm trying to remove duplicates as google.com or hotmail.com etc comes up in the output 3-4 times, is there a delete command to remove duplicates?


Ummmm why delete them when you could just set them and check if it is defined skip adding it again.
You should delete cmd.exe and it is completely related to everything on this forum. Everyone should delete cmd.exe it is sound advice.

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

Re: String Manipulation Question

#7 Post by orange_batch » 14 Jun 2011 21:01

Clept, shut up if you aren't going to help people. This is a place for helping and learning, not inane banter, it's becoming tiring.

Most people that post here are not experts, and beginners might take your malicious advice seriously which they do not deserve. On top of that, you're derailing topics. This site is heavily catalogued by search engines, so it applies to everybody looking for answers that don't sign up to ask a question.
Last edited by orange_batch on 05 Dec 2011 21:00, edited 1 time in total.

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

Re: String Manipulation Question

#8 Post by Cleptography » 14 Jun 2011 21:16

orange_batch wrote:Most people that post here are not experts, and beginners might take your malicious advice seriously which they do not deserve


Ok I apologize for my comment regarding deleting your cmd.exe if you take that seriously I have changed my point of view, instead you should unplug your computer and throw it in the trash and try to take up something easier like jump rope, or hopscotch because you have no business playing with bits and bytes.

Jayrome
Posts: 7
Joined: 13 Jun 2011 21:44
Location: Australia

Re: String Manipulation Question

#9 Post by Jayrome » 14 Jun 2011 21:28

Cleptography wrote:
Jayrome wrote:Are you trying to be a smart arse ... I'm not trying to delete cmd.exe that's completely unrelated to what my enquiry was.

!K - Thanks again for the code it worked magic, another question, i'm trying to remove duplicates as google.com or hotmail.com etc comes up in the output 3-4 times, is there a delete command to remove duplicates?


Ummmm why delete them when you could just set them and check if it is defined skip adding it again.
You should delete cmd.exe and it is completely related to everything on this forum. Everyone should delete cmd.exe it is sound advice.


I don't know that's why I'm asking.. instead of talking down to me like i'm stupid because I don't know, why not offer helpful advice or don't bother posting.

Anybody know which command I can use to achieve this?

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

Re: String Manipulation Question

#10 Post by Cleptography » 14 Jun 2011 21:47

You must first be broken before you can be built, and fyi I gave you your answer.
Try for /? if /?
Think of it as a real life scenario, say you have a box full of items and some are duplicates, but you only want one of each, so as you dig through the box you put a red sticker on each one, now you come across an item that you already have and have marked so you throw it out, very simple logic.

P.S. I don't give answers I give directions, if you get lost along the way at least you may discover something new.

Jayrome
Posts: 7
Joined: 13 Jun 2011 21:44
Location: Australia

Re: String Manipulation Question

#11 Post by Jayrome » 14 Jun 2011 21:54

I know what I want to achieve I don't need a real life example. But your obviously too arrogant to help anyone so stop spamming this thread.

Anyone else?

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

Re: String Manipulation Question

#12 Post by Cleptography » 14 Jun 2011 22:04

Would you like the world to wipe your bum for you as well after you take a crap. The question you are asking is not a difficult one to answer, so why don't you try doing a little google homework something like
batch > remove duplicate lines in a file.
Or if you want to move up a notch and forget this batch business as it really should be used for nothing more than automating task.
Try "Hey scripting guy how can I remove duplicate lines from a file"

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

Re: String Manipulation Question

#13 Post by orange_batch » 14 Jun 2011 22:35

Blah blah, your lack of humility only further proves my point. People need examples to learn, short of learning the entire language because you choose to be a smart-ass. There are enough people on the internet who choose rather to be high and mighty about their knowledge than share it congenially to someone kindly asking for help.

Jayrome, use IF statements. This trick uses substring replacement to check if the output contains certain words.

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
)

It should work, but not sure. You test it. :P
Last edited by orange_batch on 15 Jun 2011 02:57, edited 1 time in total.

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

Re: String Manipulation Question

#14 Post by Cleptography » 14 Jun 2011 23:51

Ok orange_**** explain now how he would check if the line exist twice without knowing which line it was?
Your example assumes that the duplicated line exist.

Jayrome
Posts: 7
Joined: 13 Jun 2011 21:44
Location: Australia

Re: String Manipulation Question

#15 Post by Jayrome » 15 Jun 2011 00:42

I ended up finding this vbscript which I was able to run in command prompt and does exactly what I need. Thanks for the help orange :)

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\users\administrator\desktop\finalurls.txt"
Set objFile = objFS.OpenTextFile(strFile)
Set d = CreateObject("Scripting.Dictionary")
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If Not InStr(strLine,"--------") >0 Then
If Not d.Exists(strLine) Then
d.Add strLine , 0
End If
End If
Loop
x=d.Items
For Each strKey In d.keys
WScript.Echo strKey
Next

Post Reply