Jump to content
Sign in to follow this  
Erlend

Extract info from txt files

Recommended Posts

Erlend

hello

i have to txt files contaning the following lines:

txt 1

---------- U:\USER.TXT
TS WinStation Name: ICA-tcp#11

txt 2

---------- U:\USER.TXT
Server Location: TESTSERVER

whats the simplest way to extract the content after : excample TESTSERVER

thanks for any help :)

Edited by Erlend

Share this post


Link to post
Share on other sites
rudi

Hi.

For analyzing TXT file's content it's in general useful to read the content to an array: It's not always the final line you will have to examine.

RegEx is flexible enough to do almost every possible search.

See help file: Autoit -> Tutorials -> Regular Expressions, especially the test snippet at the bottom of these pages.

#include <file.au3> ; for _filereadtoarray()
#include <array.au3> ; for _arraydisplay()
Dim $Content = ""
$InFile = "C:\MyTest.txt"

; transfer file's content into an array.
_FileReadToArray($InFile, $Content)

; have a look at your array. Look at element "0" holding the size of the array.
_ArrayDisplay($Content)

$LastLine = $Content[$Content[0]]
$AfterColon = StringRegExpReplace($LastLine, "(^.*: )([A-Z]+$)", "$2")
    ; (^    start of string
    ; .*    any character, as many times as possible ...
    ; : )   followed by "Colon<blank>"
    ; [A-Z] any upper case char
    ;  +    at least one occurrence
    ;  $    <end-of-string>
    ; $1    first match (^.*: )
    ; $2    2nd match ([A-Z]+ยง)
MsgBox(0, "Content after final "":"" is...", '"' & $AfterColon & '"' & @CRLF)

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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
Sign in to follow this  

×