autoitxp Posted April 25, 2011 Posted April 25, 2011 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
JohnOne Posted April 25, 2011 Posted April 25, 2011 There are a number of ways to carry out such a task You should look at these functions in the helpfile to spawn some ideas _FileCountLines FileRead FileReadLine StringSplit StringInStr _FileReadToArray AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
sahsanu Posted April 25, 2011 Posted April 25, 2011 (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 April 25, 2011 by sahsanu
wakillon Posted April 26, 2011 Posted April 26, 2011 A bit like sahsanu solution ! $sFile = @DesktopDir & "\mytext.txt" $sText = FileRead ( $sFile ) $aHold = StringRegExp ( $sText, '(?s)(?i)ID = (.*?)\r', 3 ) FileClose ( $sFile ) ConsoleWrite ( "$aHold : " & Number ( $aHold[0] ) & @Crlf ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
antonioj84 Posted December 30, 2016 Posted December 30, 2016 On 26/04/2011 at 3:13 AM, wakillon said: A bit like sahsanu solution ! $sFile = @DesktopDir & "\mytext.txt" $sText = FileRead ( $sFile ) $aHold = StringRegExp ( $sText, '(?s)(?i)ID = (.*?)\r', 3 ) FileClose ( $sFile ) ConsoleWrite ( "$aHold : " & Number ( $aHold[0] ) & @Crlf ) this example does not work
wakillon Posted December 30, 2016 Posted December 30, 2016 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.0 - WIN 8.1 X64 - Other Example Scripts
antonioj84 Posted December 30, 2016 Posted December 30, 2016 (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 December 30, 2016 by antonioj84
wakillon Posted December 30, 2016 Posted December 30, 2016 Try to use the example with "text.txt" instead of "mytext.txt" AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
antonioj84 Posted December 30, 2016 Posted December 30, 2016 5 minutes ago, wakillon said: Try to use the example with "text.txt" instead of "mytext.txt" no change
wakillon Posted December 30, 2016 Posted December 30, 2016 Try this $sFile = @DesktopDir & "\text.txt" ConsoleWrite ( 'FileExists ? : ' & FileExists ( $sFile ) & @Crlf ) If the text file is well on your Desktop, this script will return 1 AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
antonioj84 Posted December 30, 2016 Posted December 30, 2016 it did return 1, i am using the latest autoit beta with windows 10
wakillon Posted December 30, 2016 Posted December 30, 2016 (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 December 30, 2016 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
careca Posted December 31, 2016 Posted December 31, 2016 22 hours ago, wakillon said: Try to use the example with "text.txt" instead of "mytext.txt" Exactly, and it worked here. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. 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. 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 Au3Record.exe
wakillon Posted December 31, 2016 Posted December 31, 2016 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.0 - WIN 8.1 X64 - Other Example Scripts
mikell Posted December 31, 2016 Posted December 31, 2016 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]))
wakillon Posted December 31, 2016 Posted December 31, 2016 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.0 - WIN 8.1 X64 - Other Example Scripts
antonioj84 Posted January 2, 2017 Posted January 2, 2017 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
mikell Posted January 2, 2017 Posted January 2, 2017 ;$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")
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now