Auio42TheWin

"printing" out occurences and manipulating sort of?

14 posts in this topic

Hello, people. I have been searching the forums for an example of how to do this, but I just don't know how to word it.

I have found examples of how to search a text file for how many occurences of a word appears, but how do I do that and trim around it in certain directions? Gah. It's so confusing trying to explain.

Let's say I have a text file that saids this : 

dasdsad4|62530 No.
342344|62530 Teehee.
fsdfsd4|62530 I don't care.
gdfgd4|62530 So much pie!
23234|62530 Okay
fsdfs4|62530 Please give me pie.
adasd4|62530 Just watch
23234|62530 Autoit Rocks.
asdasd4|62530 heh
23234|62530 LOL
 
How would I search for each occurrence of "4|62530" and delete all text to the left of it and "4|62530" itself to leave me with just a word like " Please give me pie." 
 
and consolewrite each?
 
I'm not asking to be spoonfed, really, I wish I could do this on my own. But I really just don't know where to start, and I'm low on time right now :sweating:

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Auio42TheWin,

One way might be like this: :)

#include <StringConstants.au3>

$sString = "dasdsad4|62530 No." & @CRLF & _
    "342344|62530 Teehee." & @CRLF & _
    "fsdfsd4|62530 I don't care." & @CRLF & _
    "gdfgd4|62530 So much pie!" & @CRLF & _
    "23234|62530 Okay" & @CRLF & _
    "fsdfs4|62530 Please give me pie." & @CRLF & _
    "adasd4|62530 Just watch" & @CRLF & _
    "23234|62530 Autoit Rocks." & @CRLF & _
    "asdasd4|62530 heh" & @CRLF & _
    "23234|62530 LOL"

; Convert to an array
$aLines = StringSplit($sString, @CRLF, $STR_ENTIRESPLIT)
; And loop through each line
For $i = 1 To $aLines[0]
    ; Extract line
    $sLine = $aLines[$i]
    ; Does it contain the required string
    If StringInStr($sLine, "4|62530") Then
        ; If so, then extract the text
        ConsoleWrite(StringRegExpReplace($sLine, ".*4\|62530\s(.*)", "$1") & @CRLF)
    EndIf
Next
Now we wait for the real RegEx gurus to do it on one pass. :D

M23

Edited by Melba23
Typo

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#include<file.au3>

Global $aFile
_FileReadToArray("test.txt" , $aFile)

for $i = 1 to $aFile[0]
    If stringinstr($aFile[$i] , "4|62530") Then consolewrite(StringRegExpReplace($aFile[$i] , ".*?4\|62530" , "") & @CRLF)
next

damn im slow, at least i was close to the reasonable suggestion..

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Auio42TheWin,

One way might be like this: :)

#include <StringConstants.au3>

$sString = "dasdsad4|62530 No." & @CRLF & _
    "342344|62530 Teehee." & @CRLF & _
    "fsdfsd4|62530 I don't care." & @CRLF & _
    "gdfgd4|62530 So much pie!" & @CRLF & _
    "23234|62530 Okay" & @CRLF & _
    "fsdfs4|62530 Please give me pie." & @CRLF & _
    "adasd4|62530 Just watch" & @CRLF & _
    "23234|62530 Autoit Rocks." & @CRLF & _
    "asdasd4|62530 heh" & @CRLF & _
    "23234|62530 LOL"

; Convert to an array
$aLines = StringSplit($sString, @CRLF, $STR_ENTIRESPLIT)
; And loop through each line
For $i = 1 To $aLines[0]
    ; Extract line
    $sLine = $aLines[$i]
    ; Does it contain the required string
    If StringInStr($sLine, "4|62530") Then
        ; If so, then extract the text
        ConsoleWrite(StringRegExpReplace($sLine, ".*4\|62530\s(.*)", "$1") & @CRLF)
    EndIf
Next
Now we wait for the real RegEx gurus to do it on one pass. :D

M23

 

what if all the text was like all on one line? (imagine what I'm about to show you not being word-wrapped) like on one line

in a text document

http://www.example.com/Something/?test=31117267;http://www.example.com/Something/?test=20642008;http://www.example.com/Something/?test=77800124;http://www.example.com/Something/?test=9255011;http://www.example.com/Something/?test=119509981;http://www.example.com/Something/?test=119509901

 and all I wanted to get was the numbers following "?test" and print each one individually? 

 

I'm sorry if I'm confusing you, I don't think I'm very good at wording this stuff. 

Edited by Auio42TheWin

Share this post


Link to post
Share on other sites

Auio42TheWin,

Just post a file - those links do not work. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Auio42TheWin,

Just post a file - those links do not work. :)

M23

oh they weren't real links, haha. they were just examples. sorry if i confused you.

Share this post


Link to post
Share on other sites

Auio42TheWin,

It is really easy to do that with a simple RegEx. But how about explaining what you are actually trying to do - we do not appreciate producing umpteen solutions to random questions. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#include <Array.au3>

$sString="http://www.example.com/Something/?test=31117267;http://www.example.com/Something/?test=20642008;http://www.example.com/Something/?test=77800124;http://www.example.com/Something/?test=9255011;http://www.example.com/Something/?test=119509981;http://www.example.com/Something/?test=119509901"

$aMatch = StringRegExp($sString , "test=(.*?);|test=(.*?)\z" , 3)

for $i = 0 to ubound($aMatch) - 1
    If $aMatch[$i] <> "" Then consolewrite($aMatch[$i] & @CRLF)
next

the regex is dirty cause i am teh suck at them.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Auio42TheWin,

It is really easy to do that with a simple RegEx. But how about explaining what you are actually trying to do - we do not appreciate producing umpteen solutions to random questions. ;)

M23

 

My dad saves a collection of links to a text file, and just copies and pastes them on one line and separates them using ";". (no idea why)

All he needs is the numbers. He does this on a separate computer, and he does this occasionally, so that's how I know. 

I want to figure out how to get the numbers behind each link separately.

So I was thinking about it, and I was all like "Dad, I think I could figure out how to do this" since I know of AutoIt.  

I've been trying to find a solution.

This would help him, and me as I could use this in the future if I came across a problem like this again.

Edited by Auio42TheWin

Share this post


Link to post
Share on other sites

Auio42TheWin,

Then why all the guff at the beginning about "pie"? :huh:

We much prefer that you give us the real information straight away. ;)

This should work: :)

#include <Array.au3>

$sString = "http://www.example.com/Something/?test=31117267;http://www.example.com/Something/?test=20642008;http://www.example.com/Something/?test=77800124;http://www.example.com/Something/?test=9255011;http://www.example.com/Something/?test=119509981;http://www.example.com/Something/?test=119509901"

$aRet = StringRegExp($sString, "(\d+)", 3)

_ArrayDisplay($aRet, "", Default, 8)
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

and you could always run a script on his box so that when he copies the url,  only the number remains to be pasted

while 1
If stringinstr(clipget() , "?test=") Then clipput(StringRegExp(clipget() , "test=(\d+)" , 3)[0])
sleep(30)
wend
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Auio42TheWin,

Then why all the guff at the beginning about "pie"? :huh:

We much prefer that you give us the real information straight away. ;)

This should work: :)

#include <Array.au3>

$sString = "http://www.example.com/Something/?test=31117267;http://www.example.com/Something/?test=20642008;http://www.example.com/Something/?test=77800124;http://www.example.com/Something/?test=9255011;http://www.example.com/Something/?test=119509981;http://www.example.com/Something/?test=119509901"

$aRet = StringRegExp($sString, "(\d+)", 3)

_ArrayDisplay($aRet, "", Default, 8)
M23

 

Sorry, the only reason I gave the example with "pie" is because I couldn't think of a better way to explain it. I'm stupid

I thought I was making it easier.  :sweating:

Thanks!

Share this post


Link to post
Share on other sites

 

and you could always run a script on his box so that when he copies the url,  only the number remains to be pasted

while 1
If stringinstr(clipget() , "?test=") Then clipput(StringRegExp(clipget() , "test=(\d+)" , 3)[0])
sleep(30)
wend

Awesome, that's like putting the cherry ontop of the pie!

Thank you, Both and Melba!  :sorcerer:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now