Re: Can BBEdit Do This?

2010-11-29 Thread Warren Michelsen
At 1:57 PM -0600 11/28/10, Christopher Stone sent email regarding Re: 
Can BBEdit Do This?:

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):


Thank you muchly for this but I've decided to go another direction. I 
have a number of droplet AppleScripts that contain a perl script and 
I use these to clean up the data files in question by doing 
find/replace operations independent of BBEdit.


I think I'll adapt one of these to have the contained Perl script 
return the value of a desired datum to the AS and let the AS output a 
text file, or perhaps have the AS tell BBEdit to create a new text 
document with the results returned by the Perl script.


Thanks though, I'll keep and study this for future reference.

--
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>


Re: Can BBEdit Do This?

2010-11-28 Thread Christopher Stone
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

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: 


Re: Can BBEdit Do This?

2010-11-27 Thread Robert A. Rosenberg

At 17:14 -0700 on 11/27/2010, Warren Michelsen wrote about Can BBEdit Do This?:


I have an assortment of data files consisting of multiple lines that are:

DataName : DatumValue

There are 20-40 lines per file -- 20-40 data per file. I am 
interested in extracting from each file just a few of the data and 
combining these into a single output file. So, I need to (for each 
open text file) find (in this example) two of the lines and output 
the data from them into a single line of the output file.


Search for
^DataName1 : DataValue1\r
and
^DataName4 : DataValue4\r
and output a single line to the output file:
DataValue1\tDataValue4\r

Repeat the above for the next open text file and add its line to the 
existing output file.


Is it possible to do this using just BBEdit's Find/Replace and such, 
without resorting to Perl or some other type of script?



Try this - I think it will work:

Look for ^DataName1 outputting DataValue1\t and ^DataName4 outputting 
DataValue4\r. If you end up with two lines in the output file than do 
a second pass changing \t\r to just \t (which will merge the two 
lines into one).


--
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>


Can BBEdit Do This?

2010-11-27 Thread Warren Michelsen
I have an assortment of data files consisting of multiple lines that are:

DataName : DatumValue

There are 20-40 lines per file -- 20-40 data per file. I am interested in 
extracting from each file just a few of the data and combining these into a 
single output file. So, I need to (for each open text file) find (in this 
example) two of the lines and output the data from them into a single line of 
the output file.

Search for 
^DataName1 : DataValue1\r
and
^DataName4 : DataValue4\r
and output a single line to the output file:
DataValue1\tDataValue4\r

Repeat the above for the next open text file and add its line to the existing 
output file.

Is it possible to do this using just BBEdit's Find/Replace and such, without 
resorting to Perl or some other type of script?


-- 
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

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: