On Nov 27, 2010, at 18:14, Warren Michelsen wrote: > Is it possible to do this using just BBEdit's Find/Replace and such, without > resorting to Perl or some other type of script? ______________________________________________________________________
Hey Warren, Not really. Here's a quick and dirty script (assumes "dataFile.txt" exists on the desktop): set f to "" & (path to desktop) & "dataFile.txt" tell application "BBEdit" try set findResult to find "^DataName(1|10|15)\\b.+" searching in front text document ¬ options {search mode:grep, starting at top:true, returning results:true} set AppleScript's text item delimiters to " : " set valueList to {} repeat with i in found matches of findResult set end of valueList to text item 2 of match_string of i end repeat set AppleScript's text item delimiters to tab set valueList to valueList as string set dataFile to open f set end of text of dataFile to valueList & linefeed save dataFile to f on error errMsg number errNum beep tell me to display dialog "Error: " & errMsg & return & "Error Number: " & errNum end try end tell Personally I'd use the Satimage.osax for my regex (again quick and dirty): # ============================================================================================== # Find Handler - Returns Specified String - Satimage.osax # ============================================================================================== on fndUsing(fndStr, returnStr, dataSource, caseSensitive, regexFlag, wholeWord, allOccurrences, stringResult) try set findResult to find text fndStr ¬ in dataSource ¬ case sensitive caseSensitive ¬ regexp regexFlag ¬ whole word wholeWord ¬ using returnStr ¬ all occurrences allOccurrences ¬ string result stringResult return findResult on error # errMsg number errNum return false end try end fndUsing tell application "BBEdit" try set textData to text of front window set foundText to fndUsing("^DataName(1|3|10|15)\\b : (.+)", "\\2", textData, ¬ false, true, false, true, true) of me set foundText to join foundText using tab # WRITE foundText TO FILE on error errMsg number errNum beep tell me to display dialog "Error: " & errMsg & return & "Error Number: " & errNum end try end tell In any case a simple task. -- Best Regards, Chris -- You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups. To post to this group, send email to bbedit@googlegroups.com To unsubscribe from this group, send email to bbedit+unsubscr...@googlegroups.com For more options, visit this group at <http://groups.google.com/group/bbedit?hl=en> If you have a feature request or would like to report a problem, please email "supp...@barebones.com" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>