String Manipulation Question
Moderator: DosItHelp
String Manipulation Question
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!
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!
Re: String Manipulation Question
Code: Select all
for /f "tokens=2 delims=/" %%a in (infile.txt) do echo,%%a>> outfile.txt
Re: String Manipulation Question
That worked great thank you!
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: String Manipulation Question
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.
Hope this helps.
Re: String Manipulation Question
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?
!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?
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: String Manipulation Question
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.
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: String Manipulation Question
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.
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.
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: String Manipulation Question
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.
Re: String Manipulation Question
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?
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: String Manipulation Question
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.
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.
Re: String Manipulation Question
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?
Anyone else?
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: String Manipulation Question
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"
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"
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: String Manipulation Question
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.
It should work, but not sure. You test it. :P
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.
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: String Manipulation Question
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.
Your example assumes that the duplicated line exist.
Re: String Manipulation Question
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
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