Re: How to remove white space between every other line?

307 views
Skip to first unread message

Patrick Woolsey

unread,
Jun 27, 2012, 8:08:57 PM6/27/12
to bbe...@googlegroups.com
lumaflux <luma...@gmail.com> sez:

>I have documents that I need to remove the white space between the first
>and second line and add a comma. For example before:
>
>1. �Qu� vas a comprar?
>2. What are you going to buy?
[...]
>
>After:
>
>1. �Qu� vas a comprar?,What are you going to buy?
[...]
>
>What would be the best way to do this in BBedit (Applescript)?
>I'm sure it's simple, but I can't get a hold on it.


Although you could use an AppleScript to do this, I suggest you instead
perform a search & replace (or Replace All) using the "Grep" option and
appropriate grep patterns.

For example, here's one way to do this:

Find: ^(.+?)\r(.+?)$

Replace: \1,\2

In the Find pattern, use ^ to start matching at the beginning of a line, then
.+? to do a non-greedy match of the entire first line, and wrap that in
parentheses (.+?) to make it a reusable subpattern. Next, use \r to match
the line break between the first and second lines, then (.+?) again to
match the second line, and $ to stop the match at the end of the second
line.

The Replace pattern will replace the entire match (both lines) with the
contents of the first line \1 then the literal comma "," you wish to add,
and finally the contents of the second line \2.


[For more info about using grep patterns -- also known as regular
expressions -- plus various examples, please see Chapter 8 of BBEdit's PDF
manual, which you can open at any time by choosing Help -> User Manual.]


Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com>
P.O. Box 1048, Bedford, MA 01730-1048

Christopher Stone

unread,
Jun 27, 2012, 11:37:22 PM6/27/12
to bbe...@googlegroups.com
On Jun 27, 2012, at 16:53, lumaflux wrote:
I have documents that I need to remove the white space between the first and second line and add a comma.
______________________________________________________________________

Hey There,

If you want to automate that on a per document basis you can use something like this:

tell application "BBEdit"
  tell text of front text window
    replace "^(.+?)\\r(.+?)$" using "\\1,\\2" options {search mode:grep, case sensitive:false, starting at top:true}
  end tell
end tell

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages