autoitxp

Read value from text file

20 posts in this topic

Hi

my text.txt file got data like this i just want to pick or get value of ID how to do that need ur help

name= xxxx

subject = xxxx

email = xxxx

ID = 23123

number = xxxxxx

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Maybe this could help you to start with your script:

$result = StringRegExp(FileRead("text.txt"),"ID\s=\s(.*)",1)
If IsArray($result) Then
    MsgBox(0,"","ID is " & $result[0])
Else
    MsgBox(0,"","I didn't find the ID")
EndIf
Edited by sahsanu

Share this post


Link to post
Share on other sites
44 minutes ago, antonioj84 said:

this example does not work

$sFile = @DesktopDir & "\mytext.txt"
$sText = FileRead ( $sFile )
$aHold = StringRegExp ( $sText, '(?s)(?i)ID = (.*?)\r', 3 )
ConsoleWrite ( "$aHold : " & Number ( $aHold[0] ) & @Crlf )

Script return well the Id value, $aHold : 23123 


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

4 minutes ago, wakillon said:
$sFile = @DesktopDir & "\mytext.txt"
$sText = FileRead ( $sFile )
$aHold = StringRegExp ( $sText, '(?s)(?i)ID = (.*?)\r', 3 )
ConsoleWrite ( "$aHold : " & Number ( $aHold[0] ) & @Crlf )

Script return well the Id value, $aHold : 23123 

 
 
 
it returns value 0
However, the code below works.

$result = StringRegExp(FileRead("getEMVRids.txt"),"ID\s=\s(.*)",1)
If IsArray($result) Then
    MsgBox(0,"","ID is " & $result[0])
Else
    MsgBox(0,"","I didn't find the ID")
EndIf










my text file

emvRids.rids[x].addContactlessData = 1
emvRids.rids[x].rid = A000000025
etype = 4
emvRids.rids[x].addContactlessData = 1
emvRids.rids[x].rid = A000000065
etype = 5
emvRids.rids[x].addContactlessData = 0
emvRids.rids[x].rid = A000000152
etype = 6
emvRids.rids[x].addContactlessData = 0

ID = 23123
$result = StringRegExp(FileRead("text.txt"),"ID\s=\s(.*)",1)
If IsArray($result) Then
    MsgBox(0,"","ID is " & $result[0])
Else
    MsgBox(0,"","I didn't find the ID")
EndIf
Edited by antonioj84

Share this post


Link to post
Share on other sites

Try to use the example with "text.txt" instead of "mytext.txt"


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
5 minutes ago, wakillon said:

Try to use the example with "text.txt" instead of "mytext.txt"

no change

readfileCapture.JPG

Share this post


Link to post
Share on other sites

it did return 1, i am using the latest autoit beta  with windows 10

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

35 minutes ago, antonioj84 said:

it did return 1, i am using the latest autoit beta  with windows 10

For me with current release or latest beta with Win 7 or Win 8.1 it return well 23123

text.txt

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
22 hours ago, wakillon said:

Try to use the example with "text.txt" instead of "mytext.txt"

Exactly, and it worked here.

screenshot - 31122016-1441.jpg


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

Thanks Careca

i really don't know why antonioj84 can't get it to work.

Are you using Win 10 ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Using the txt file provided by antonioj84 :

emvRids.rids[x].addContactlessData = 1
emvRids.rids[x].rid = A000000025
etype = 4
emvRids.rids[x].addContactlessData = 1
emvRids.rids[x].rid = A000000065
etype = 5
emvRids.rids[x].addContactlessData = 0
emvRids.rids[x].rid = A000000152
etype = 6
emvRids.rids[x].addContactlessData = 0

ID = 23123

There are many reasons for this regex to fail. One among others :

$result = StringRegExp(FileRead("text.txt"), '(?s)(?i)ID = (.*?)\r', 3 )

MsgBox(0,"","$result[0] = " & $result[0] & @crlf & "Number($result[0]) = " & Number($result[0]))

:)

Share this post


Link to post
Share on other sites

The better way to ask for help is to show the text on which he try the script

and not to edit his post (for insert his text) after i have received the notification...


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Right   :)

Share this post


Link to post
Share on other sites

#18 ·  Posted

On 31/12/2016 at 11:05 AM, mikell said:

Using the txt file provided by antonioj84 :

emvRids.rids[x].addContactlessData = 1
emvRids.rids[x].rid = A000000025
etype = 4
emvRids.rids[x].addContactlessData = 1
emvRids.rids[x].rid = A000000065
etype = 5
emvRids.rids[x].addContactlessData = 0
emvRids.rids[x].rid = A000000152
etype = 6
emvRids.rids[x].addContactlessData = 0

ID = 23123

There are many reasons for this regex to fail. One among others :

$result = StringRegExp(FileRead("text.txt"), '(?s)(?i)ID = (.*?)\r', 3 )

MsgBox(0,"","$result[0] = " & $result[0] & @crlf & "Number($result[0]) = " & Number($result[0]))

:)

 

here is the file

mytext.txt

Share this post


Link to post
Share on other sites

#19 ·  Posted

;$result = StringRegExp(FileRead("text.txt"),"ID\s=\s(.*)",1)

#Include <Array.au3>

$result = StringRegExp(FileRead("text.txt"), '(?s)(?i)ID = (.*?)\r', 3 )
_ArrayDisplay($result, "1")

; now remove the useless options. then it works BUT it will fail if the text contains no trailing newline sequence because of the final \r 

$result = StringRegExp(FileRead("text.txt"), 'ID = (.*?)\r', 3 )
_ArrayDisplay($result, "2")

; if we remove the \r then we get an empty string - the lazy ? makes (.*?) able to match an empty string

$result = StringRegExp(FileRead("text.txt"), 'ID = (.*?)', 3 )
_ArrayDisplay($result, "3")

; here it is

$result = StringRegExp(FileRead("text.txt"), 'ID = (.*)', 3 )
_ArrayDisplay($result, "4")

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

IT works thank you all and Mikell

Capture2file.JPG

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