Appending to a line

29 views
Skip to first unread message

Dave Simpson

unread,
May 8, 2022, 12:04:59 PM5/8/22
to BBEdit Talk
I've looked at Creating Subpatterns in then manual but I'm sorry but a lot of the syntax is going over my head :-(

I'm not a power user and generally just need to do straightforward search/replace.

I want to search a text file.
Every time a line begins 2 PLAC
I want to append the word England to the end of the line.

Hope someone can help

Christian Boyce

unread,
May 8, 2022, 1:18:13 PM5/8/22
to bbe...@googlegroups.com, quar...@gmail.com
This GREP stuff is really worth learning. 

However, I can help you with this particular problem, because it’s easy.

You want to do a GREP search, with search string like this:

^(2 PLAC)(.*)$

And you want to replace with this:

\1\2 England

That’s it. Try it.

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://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 bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/39d3f39e-7a63-4952-8593-a9240f0da066n%40googlegroups.com.


Dave Simpson

unread,
May 8, 2022, 4:06:59 PM5/8/22
to BBEdit Talk
Many thanks Christian, it much appreciated.

Bucky Junior

unread,
May 8, 2022, 11:14:01 PM5/8/22
to BBEdit Talk
I was fortunate to learn some bits of regex/grep from helpful people on this list who not only showed an answer to a question but explained what was happening. While this search/replace using grep is quite simple, it’s not always obvious to everyone.


> On May 8, 2022, at 1:36 PM, Dave Simpson <quar...@gmail.com> wrote:
>
> You want to do a GREP search, with search string like this:
>
> ^(2 PLAC)(.*)$
>
> And you want to replace with this:
>
> \1\2 England
>
> That’s it. Try it.
>

In the search pattern:
^ means start at the beginning of a line
(2 PLAC) parentheses bracket the search text and “remembers" it. In this case, it is known characters. Grep lets you search for unknown/partially known characters too.
(.*) second parentheses uses “.” As any character except newline or carriage return. The asterisk expands that to zero or more characters.
$ means the end of the line.

The replacement is
\1 first parentheses “remembered” pattern
\2 follow that with the second
England end the replacement with a space and then the literal text “England”

That’s mostly this grep/replace. You know the BBEdit Manual has lots more.
Bucky
Message has been deleted

Christian Boyce

unread,
May 10, 2022, 10:09:34 PM5/10/22
to bbe...@googlegroups.com
Great explanation Bucky— I shouldn’t have been so lazy as to not give an explanation myself! Thanks for doing what I should have done. It’s perfect.

Dave Simpson

unread,
May 11, 2022, 8:46:40 AM5/11/22
to BBEdit Talk
Thanks Bucky

That helps me a lot.
Dave

Roger Moffat

unread,
May 11, 2022, 12:40:30 PM5/11/22
to bbe...@googlegroups.com
I would add to this that the original poster probably wanted to add

, England

to the end of each place, rather than just 

England

So replace with

\12\, England

is required.

Roger

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://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 bbedit+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages