Jump to content

Get text from notepad


Recommended Posts

Hello everyone.

I'm having a bit of trouble with some script I made.

Ok, so I'm having a Wordpad text file that goes by log.doc and it looks like this:

NR: 8612457    NAME: x1     ARGV: 123         * 1
NR: 86124578   NAME: x12    ARGV: 1234        * 2
NR: 861245789  NAME: x123   ARGV: 12345       * 3

I've managed to make a script that copies the data from it, it looks like this:

WinWaitActive("log.doc - WordPad");
Sleep(200)
Send("^f")
Sleep(100)
Send("NR")
Send("{ENTER}")
Sleep(100)
Send("{ESC}")
Sleep(100)
Send("{UP}")
Send("{LEFT 4}")
Sleep(100)
Send("+^{RIGHT 2}")
Sleep(50)
Send("+^{RIGHT 2}")
Sleep(50)
Send("+^{RIGHT 2}")
Sleep(50)
Send("+^{RIGHT 1}")
Sleep(50)
Send("^c")
Sleep(300)

So, I want autoit to use CTRL+SHIFT and RIGHT to select the text, but, when it selects it, it goes with all the spaces too, like:

a *space**space**space**space**space**space**space*
not
a

If the spaces were the same amount (like 12 spaces or smth like that, I would've use the replace tool from WordPad and replace the spaces with nothing so that the script can select only the number(or text) that i want to select.

Any help?

Thanks.

Link to comment
Share on other sites

You don't need to open the log file in Notepad to get its content.

Simply use FileRead.

Also, to get rid of all white spaces - that is simple, use StringReplace (if you want to keep the end of line).

Functions to look up: FileRead, StringReplace, StringStripWS ... al of them have examples.

$file_content = FileRead("my file here")
$without_spaces = StringReplace($file_content, " ", "")
MsgBox(0, "Log without spaces", $without_spaces)

$Strip_double_space = StringStripWS($file_content, 4)
MsgBox(0, "Log without double-or-more spaces", $Strip_double_space)

actually - what especially do you need to get from that file? what info? because the way you go is not the easiest one.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Thank you very much for your reply.

Well, I got a program that has to check this numbers, so AutoIT does this:

Opens log.doc, then presses CTRL F and searches for the end of the line, for example:

It start FIND and sends "good" and than it sends {ENTER} so that "good" is selected.

NR: 8.61.24.57    NAME: x1     ARGV: 123         * bad
NR: 86.12.45.78   NAME: x12    ARGV: 1234        * bad
NR: 861.2.45.789  NAME: x123   ARGV: 12345       * [b][color=red]good[/color][/b]

And then, it does this:

Send("{ESC}"); closes the FIND box
Sleep(100)
Send("{CTRLDOWN}")
Send("{LEFT 15}"); it jumps to the start of numbers after NR.
Send("{CTRLUP}")
Sleep(100)
Send("+^{RIGHT 2}")
Sleep(50)
Send("+^{RIGHT 2}")
Sleep(50)
Send("+^{RIGHT 2}")
Sleep(50)
Send("+^{RIGHT 1}"); all this CTRL SHIFT RIGHT selects the number (e.g: [b]861.2.45.789*space*[/b])
Sleep(50)
Send("^c")
Sleep(300)
Run("cmd")
Sleep(450)
Send("qwert.exe")
Sleep(150)
Send("{ENTER}")
Sleep(100)
WinWaitActive("QWERT.exe")
Sleep(650)
Send("^v"); send the NR to qwert.
Sleep(1050)
Send("{ALT DOWN}")
Send("{TAB 2}")
Send("{ALT UP}")
WinWaitActive("log.doc - WordPad");
Sleep(450)
Send("^{RIGHT 3}")
Sleep(100)
Send("+^{RIGHT 1}"); selects the [b]"name"*space*[/b]
Sleep(150)
Send("^c"); Copies the name so it can be pasted to QWERT.exe
$name = ClipGet()
Sleep(350)
Send("!{TAB 1}");Swtiches back to QWERT.exe
Sleep(150)
WinWaitActive("QWERT.exe")
Send("{ENTER}"); inserts the number and press ok
Sleep(6000)
Send("{TAB 2}"); this 2 tabs plus the space accepts a warning.
Sleep(150)
Send("{SPACE}")
Sleep(30000)
Send($name); sends the NAME to QWERT after it processes the number.
Sleep(50)
Send("{BS 1}"); clears the *space* from [b]"name"[/b]
Sleep(600)
Send("{TAB}"); selects the ARGV tab
Sleep(500)
Send("{ALT DOWN}")
Send("{TAB}"); goes back to log.doc
Send("{ALT UP}")
Sleep(200)
WinWaitActive("log.doc - WordPad");
Sleep(100)
Send("^{RIGHT 3}")
Sleep(50)
Send("+^{RIGHT 1}"); selects ARGV
Sleep(150)
Send("^c");copies ARGV
$argv = ClipGet()
Sleep(100)
Send("{ALT DOWN}")
Send("{TAB}"); Switches back to QWERT.exe
Send("{ALT UP}")
Sleep(1000)
Send($argv)
Sleep(500)
Send("{BS}")
Sleep(200)
Send("{ENTER}");Inserts ARGV and sends {ENTER}

That`s the script ATM, I need to make it someway to get the whole word after ARGV: because some words are okey, like 123456, and when it goes by CTRL SHIFT RIGHT, it selects 123456, but some are like 1@3456, so when it goes by CTRL SHIFT RIGHT, it selects only 1@ because it gets @ like a break.

Thank you.

Link to comment
Share on other sites

I've put a little bit of work in this script - it gets all the content in array elements - to retrieve the content you need it is easy once you are a bit familiar with arrays.

Second part of the script is just as a demo.

Read the comments.

#Include <Array.au3>
#Include <File.au3>
#Include <String.au3>

Dim $MyArray[4]                                     ;comment this (testing)
;Dim $MyArray                                       ;YOU NEED To Use THIS line
;_FileReadToArray("my log file here", $MyArray)     ;YOU NEED To Use THIS line

$MyArray[0] = 3
$MyArray[1] = "NR: 8.61.24.57    NAME: x1     ARGV: 123         * bad"      ;comment this (testing)
$MyArray[2] = "NR: 86.12.45.78   NAME: x12    ARGV: 1234        * bad"      ;comment this (testing)
$MyArray[3] = "NR: 861.2.45.789  NAME: x123   ARGV: 12345       * [b][color=red]good[/color][/b]"   ;comment this (testing)

Dim $MyResultArray[$MyArray[0]+1][4]

$temp = ""
For $i = 1 To $MyArray[0]
    $temp = _StringBetween($MyArray[$i], "NR:", "NAME")
    $MyResultArray[$i][0] = StringStripWS($temp[0], 3)
    $temp = _StringBetween($MyArray[$i], "NAME:", "ARGV")
    $MyResultArray[$i][1] = StringStripWS($temp[0], 3)
    $temp = _StringBetween($MyArray[$i], "ARGV:", "*")
    $MyResultArray[$i][2] = StringStripWS($temp[0], 3)
    $temp = StringMid($MyArray[$i], StringInStr($MyArray[$i], "* "))
    $MyResultArray[$i][3] = StringStripWS($temp, 3)
Next
_ArrayDisplay($MyResultArray)

;The following part is optional and I did it just for educational purpose
;Up to this point you have an array containig all the entries in your log file
;to see if an entry is good or bad - you need to test only the [3] element from every row.
;
;To fully benefit out of this example, you need to red about arrays and to have a play with them

Dim $MyGoodArray[1][4]
Dim $MyBadArray[1][4]

_GetGoodEntries($MyResultArray)
_ArrayDisplay($MyGoodArray, "Good Entries")

_GetBadEntries($MyResultArray)
_ArrayDisplay($MyBadArray, "Bad Entries")

Func _GetGoodEntries(ByRef $ARR)
    Local $counter = 0
    For $i = 1 To UBound($ARR)-1
        If StringInStr($ARR[$i][3], "good") Then
            ReDim $MyGoodArray[$counter+1][4]
            $MyGoodArray[$counter][0] = $ARR[$i][0]
            $MyGoodArray[$counter][1] = $ARR[$i][1]
            $MyGoodArray[$counter][2] = $ARR[$i][2]
            $MyGoodArray[$counter][3] = $ARR[$i][3]
            $counter += 1
        EndIf
    Next
EndFunc
Func _GetBadEntries(ByRef $ARR)
    Local $counter = 0
    For $i = 1 To UBound($ARR)-1
        If StringInStr($ARR[$i][3], "bad") Then
            ReDim $MyBadArray[$counter+1][4]
            $MyBadArray[$counter][0] = $ARR[$i][0]
            $MyBadArray[$counter][1] = $ARR[$i][1]
            $MyBadArray[$counter][2] = $ARR[$i][2]
            $MyBadArray[$counter][3] = $ARR[$i][3]
            $counter += 1
        EndIf
    Next
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...