On Wednesday, May 31, 2017 at 7:56:19 AM UTC-4, mrcmrc wrote:
>
> Hi all,
> I need some help in order to create a GREP pattern that let me transform a
> text file. In this text file there are a list of glossary terms like this:
> ....
>
Sam's approach did not work for me when I tested it here using BBEdit 8.2.6.
There are 2 problems as I see it -
first the need to identify the phrase being defined, i.e., xxxx xxxxx -
second to handle the extra lines, whether parts of the definitions or blank
lines
I've often found the simplest approach is to use several passes as shown
below
================================
original
================================
acceptor — A dopant material, such as boron, which has fewer outer shell
electrons than required in an otherwise balanced crystal structure,
providing a hole, which can accept a free electron.
activated shelf life — The period of time, at a specified temperature, that
a charged battery can be stored before its capacity falls to an unusable
level.
activation voltage(s) — The voltage(s) at which a charge controller will
take action to protect the batteries.
================================
find=^([^—\r]+)—.* replace=\t\1
first pass: marks the first line with a TAB and also trims the " - " and
the remainder of the line
================================
acceptor
electrons than required in an otherwise balanced crystal structure,
providing a hole, which can accept a free electron.
activated shelf life
a charged battery can be stored before its capacity falls to an unusable
level.
activation voltage(s)
take action to protect the batteries.
================================
find=^[^\t].*\r replace=
second pass: delete all lines which do not begin with a leading TAB
================================
acceptor
activated shelf life
activation voltage(s)
================================
find=^\t replace=
final pass: delete the TABs
================================
acceptor
activated shelf life
activation voltage(s)
When I will frequently need to re-use such a multi-pass solution I simply
use BBEdit's scripting to
record a script (a sequence of Find/Replace operations) and Save it under a
helpful name.
In this case the recorded script would read (in Script Editor) as:
*tell* application "BBEdit 8.2.6"
activate
replace "^([^—\\r]+)—.*" using "\\t\\1" searching in text 1 *of* text
document 1 options {search mode:grep, starting at top:false, wrap around:
false, backwards:false, case sensitive:false, match words:false, extend
selection:false}
replace "^[^\\t].*\\r" using "" searching in text 1 *of* text document 1
options {search mode:grep, starting at top:false, wrap around:false,
backwards:false, case sensitive:false, match words:false, extend selection:
false}
replace "^\\t" using "" searching in text 1 *of* text document 1 options
{search
mode:grep, starting at top:false, wrap around:false, backwards:false, case
sensitive:false, match words:false, extend selection:false}
*end* *tell*
Hope this helps,
Garth Fletcher
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.