Help with text search

Hello

Im a newbie at applescript so bear with me. Im trying to create a script that will:

  1. search multiple text files in an network folder for a 6 digit number
  2. show the results of the search
  3. copy the results to the clipboard

the text files are job files that our company uses. Each job has a 6 digit number then data after it. for example:

600001
text
text
text
600002
text
text
text
text
600003

I want to be able to do a search for 600001 and it will show the results plus copy the text after the job number but stop at the next 6 digit job number. Is this possible? Ive written a script that only does the search through textwrangler but nothing else.

Any ideas? Thanks.

set theFile to POSIX path of ((choose file) as string)

set theLines to every paragraph of (do shell script "cat " & quoted form of theFile) 

set theData to {}
set theBuffer to {}
repeat with thisLine in theLines
	if (do shell script "echo " & quoted form of thisLine & " | tr -d [0-9]")'s length = 0 and thisLine's length = 6 and theBuffer is not {} then
		set AppleScript's text item delimiters to return
		set end of theData to (theBuffer as string)
		set AppleScript's text item delimiters to ""
		set theBuffer to {}
	end if
	set end of theBuffer to contents of thisLine
end repeat

if theBuffer is not {} then
	set AppleScript's text item delimiters to return
	set end of theData to (theBuffer as string)
	set AppleScript's text item delimiters to ""
end if

return theData

Thank you for that, how would i integrate a window that pops up when the script is run asking what job number you are looking for? The search script that i have at the moment is:



tell application "TextWrangler"
	activate
	
	set jobNumber to text returned of (display dialog "Please enter the job number:" default answer "")
	find jobNumber searching in {alias "Tin:Text from PICK:"} options {search mode:grep, case sensitive:false, match words:false, extend selection:false, showing results:true}
	
	
	
end tell

I cant seem to get the 2 to work together. Any Suggestions?