AutoHotkey Community

It is currently May 27th, 2012, 2:36 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: February 16th, 2010, 9:54 pm 
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]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2010, 10:41 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2010, 10:58 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2010, 11:01 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6071
Location: San Diego, California
Saying the same things as others, just slower to post :oops:

May I suggest looking at the following commands:

search the text for a specific word
http://www.autohotkey.com/docs/commands ... GetPos.htm

if you just want to see if the word is in a varable
http://www.autohotkey.com/docs/commands/IfInString.htm

copy the text that is right next to it
http://www.autohotkey.com/docs/commands/StringMid.htm

you might need this to determine the length of the 'word'
or you could just count and put 10 in a variable 'License#1 ' (including the trailing space).
http://www.autohotkey.com/docs/commands/StringLen.htm

I DO need copied to clipboard
http://www.autohotkey.com/docs/misc/Clipboard.htm

You don't describe how you plan to read the file.
Autohotkey has various methods to read a file, here is the command list
http://www.autohotkey.com/docs/commands.htm

This command would probably work the easiest, though maybe no the best. It reads a line of text and if License# and the actualt number are on the same text line the above commands would easily allow you to copy the text from the "#1" to the end of the line.
http://www.autohotkey.com/docs/commands ... adLine.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2010, 11:02 pm 
Offline

Joined: December 8th, 2006, 5:17 am
Posts: 248
Location: Sydney Australia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thank you guys very much
PostPosted: February 18th, 2010, 2:41 am 
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!


Report this post
Top
  
Reply with quote  
 Post subject: O man
PostPosted: February 18th, 2010, 2:55 am 
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,


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, Google [Bot], Google Feedfetcher, rbrtryn and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group