 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Strickt1 Guest
|
Posted: Tue Feb 16, 2010 8:54 pm Post subject: Simple Script to Search and Copy adjacent Text. |
|
|
I have a text file which has quite a bit of text that I have to check on a regular basis. I was wondering if there was a way of using autohotkey to create a script that will search the text for a specific word and then copy the text that is right next to it?
I know the basics of scripting and have gone through the tutorials, and I think I would be able to get the copied data where I need to use it.
For example I would like to be able to find and copy to clipboard the license # from the following example,
| Quote: | Dog license number registered to Jane Doe
Burmington California
2 warnings given, has following dog tags recorded.
Jane Doe, Dog Name Scruffy, License#1 abcd1234
123 roadname st.
Burmington, CA. 33124
Record # 92211LG |
I want to create a script that would search out "License#1" but then copy and paste the actual license # listed just to the right of that, in this example it's abcd1234. Because the license number will always change I don't think I can have it search for that, I need to have this script search for License#1 as that doesn't change, but it is the license number adjacent to that (abcd1234) that I DO need copied to clipboard.
Thank you very much for any help[/quote] |
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
Posted: Tue Feb 16, 2010 9:41 pm Post subject: |
|
|
You'll want StringGetPos to find "Record #" and StringMid to get the text after it.
How you get the text into a variable for autohotkey to search it is dependant on how you access it.
FileRead can read the contents of a text file.
ControlGetText would be easiest if you already have the file open in Notepad. |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Tue Feb 16, 2010 9:58 pm Post subject: |
|
|
Probably the easiest way to do that would be to use regex since the standard string manipulation functions don't handle vertical whitespace well:
| Code: | var=
(
Dog license number registered to Jane Doe
Burmington California
2 warnings given, has following dog tags recorded.
Jane Doe, Dog Name Scruffy, License#1 abcd1234
123 roadname st.
Burmington, CA. 33124
Record # 92211LG
)
RegExMatch(var,"is)(?<=License#1 )\S+",m) ; will match any non-whitespace characters preceded by "License#1 "
MsgBox % m
return |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
|
| Back to top |
|
 |
poo_noo
Joined: 08 Dec 2006 Posts: 248 Location: Sydney Australia
|
Posted: Tue Feb 16, 2010 10:02 pm Post subject: |
|
|
You guys are too quick for me
heres my attempt
| Code: | theData =
(
Dog license number registered to Jane Doe
Burmington California
2 warnings given, has following dog tags recorded.
Jane Doe, Dog Name Scruffy, License#1 abcd1234
123 roadname st.
Burmington, CA. 33124
Record # 92211LG
Jane Doe, Dog Name Dog2, License#1 TEST1234
Jane Doe, Dog Name Scruffy3, License#1 Test12345
Jane Doe, Dog Name Scruffyddd, License#1 abcd12346
)
; read the data.
Loop, parse, theData, `n, `r ; Specifying `n prior to `r allows both Windows and Unix files to be parsed.
{
; skip blank lines
If A_LoopField =
Continue
; look for the line that has License#1 in it
IfInString, A_LoopField, License#1
{
; get the licence number by RegExReplace & stored in variable 'licences'
licences .= RegExReplace(A_LoopField, "^.*License#1 (.*)", "$1") . "`n"
}
}
msgbox outta loop`n`n%licences%
|
_________________ Paul O |
|
| Back to top |
|
 |
Strickt1 Guest
|
Posted: Thu Feb 18, 2010 1:41 am Post subject: Thank you guys very much |
|
|
| Thanks so much for your assistance, I will research and put these methods to use and let you know how it goes. I'm still learning so my followup may be some time out but atleast I have somewhere to start, and some example code to work with. Thank you! |
|
| Back to top |
|
 |
Strickt1 Guest
|
Posted: Thu Feb 18, 2010 1:55 am Post subject: O man |
|
|
I can't thank you enough, you have no idea how much easier this will make my work once I got this put together. I know it's possible now, I just need to configure it.
Thanks again, |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|