Need to remove blank lines

56 views
Skip to first unread message

Howard

unread,
Jan 13, 2021, 5:28:46 PM1/13/21
to BBEdit Talk
I have several hundred lines of data. Each observation occupies two lines; however, in a number of places (not all) a blank line exists between observations. For example, between the first data element, Max Scherzer, and the second one, Justin Verlander, is a blank line. (A sample is below.)  

The first two rows contain the column names.

How can I remove all the blank lines? After doing that, I want to be able to paste the data back into a spreadsheet for further manipulation.

Rk Name Player Matching W L W-Lpct ERA GS CG SHO SV IP H R ER HR BB SO WHIP SB CS WPA Tm
1 Max Scherzer\scherma01 Max Scherzer 84 56 8 0.875 1.56 84 8 4 0 584.1 294 107 101 53 89 787 0.66 16 5 21.1 WSN
2 Justin Verlander\verlaju01 Justin Verlander 80 49 11 0.817 1.72 80 5 3 0 554.0 269 114 106 59 88 693 0.64 9 7 18.9 DETHOU
3 Zack Greinke\greinza01 Zack Greinke 79 51 6 0.895 1.63 79 1 1 0 529.0 306 98 96 37 68 524 0.71 11 11 17.5 LADARIHOU
4 Clayton Kershaw\kershcl01 Clayton Kershaw 75 48 7 0.873 1.38 75 6 5 0 509.1 254 83 78 32 56 605 0.61 5 8 17.4 LAD

Luis Speciale

unread,
Jan 13, 2021, 5:54:49 PM1/13/21
to bbe...@googlegroups.com

Find

\n\n

Replace

\n

Christopher Stone

unread,
Jan 13, 2021, 6:01:42 PM1/13/21
to BBEdit-Talk
On 01/13/2021, at 16:28, Howard <leadwi...@gmail.com> wrote:
I have several hundred lines of data. Each observation occupies two lines; however, in a number of places (not all) a blank line exists between observations. For example, between the first data element, Max Scherzer, and the second one, Justin Verlander, is a blank line. (A sample is below.)  

The first two rows contain the column names.

How can I remove all the blank lines?


Hey Howard,

It looks like your blank lines are actually empty records with tab separators.

Personally I'd use a text filter for this.

Save this sed script to a text file.

#!/usr/bin/env bash
sed -E '/^[[:blank:]]*$/d'

In this folder:

~/Library/Application Support/BBEdit/Text Filters/<Your Filter Name>.sh

Run from BBEdit Menu Bar › Text › Apply Text Filter › Your_Filter_Name.

If you're going to use it often then give it a keyboard shortcut in BBEdit's Menus & Shortcuts prefs.

If you just want to use a regular expression in the Find/Replace window then use this pattern:

^\h*$\R+

Replace with nothing.

--
Best Regards,
Chris

Neil Faiman

unread,
Jan 13, 2021, 6:04:47 PM1/13/21
to BBEdit Talk Mailing List
Edit > Process Lines Containing ...

In the dialog box, Find lines containing: . (a single period character), check "Grep", check "Copy to clipboard", Click "Process".

Now the clipboard contains all the non-blank lines from the document (i.e., all the lines containing any character), so Cmd-A, Cmd-V (Select All, Paste) will replace the document contents with the non-blank lines.

Neil Faiman

Tom Robinson

unread,
Jan 13, 2021, 6:15:52 PM1/13/21
to BBEdit Talk
Huh, I was going to say use Process Lines Containing, but search for ^$ and select Grep and Delete matched lines — saves the copying & pasting step.

But BBEdit isn’t finding the blank lines. ^$ does work in the normal Find dialog.

Cheers

Neil Faiman

unread,
Jan 13, 2021, 6:24:13 PM1/13/21
to BBEdit Talk Mailing List
Yep, that was the first thing I tried, too. The more elaborate scheme I described below was my workaround when that didn't work.
> --
> 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/4B9B0AA2-D814-49BF-AEBF-249B46D40246%40gmail.com.

Christopher Stone

unread,
Jan 13, 2021, 6:56:14 PM1/13/21
to BBEdit-Talk
On 01/13/2021, at 17:15, Tom Robinson <barefo...@gmail.com> wrote:
Huh, I was going to say use Process Lines Containing, but search for ^$ and select Grep and Delete matched lines — saves the copying & pasting step.

But BBEdit isn’t finding the blank lines.


Hey Tom,

It works fine for me, but I had to allow for the horizontal whitespace in Howard's example.



^$ does work in the normal Find dialog.

It shouldn't, because there's whitespace in those, thar lines:


--
Best Regards,
Chris

Tom Robinson

unread,
Jan 13, 2021, 8:00:31 PM1/13/21
to BBEdit Talk
Cool, but it still fails when trying to remove completely empty lines in a test document.

Bruce Van Allen

unread,
Jan 13, 2021, 8:22:08 PM1/13/21
to BBEdit Talk

I think people might be getting differing behavior because trying with different versions of BBEdit.

I’m running the latest beta (version 13.5.5 build 415089), and my “Process Lines Containing…” dialogue looks different from the image Christopher posted. And the regex ^\s*$ does NOT work. Nor does ^\h*\$ .

What versions are y’all using?

On 13 Jan 2021, at 17:00, Tom Robinson wrote:

Cool, but it still fails when trying to remove completely empty lines in a test document.

On 2021-01-14, at 12:56, Christopher Stone <listmei...@gmail.com> wrote:

On 01/13/2021, at 17:15, Tom Robinson <barefo...@gmail.com <mailto:barefo...@gmail.com>> wrote:

Huh, I was going to say use Process Lines Containing, but search for ^$ and select Grep and Delete matched lines — saves the copying & pasting step.

But BBEdit isn’t finding the blank lines.

It works fine for me, but I had to allow for the horizontal whitespace in Howard's example.

Best Regards,

  • Bruce
Screen Shot 2021-01-13 at 5.14.24 PM.png

Christopher Stone

unread,
Jan 13, 2021, 8:59:43 PM1/13/21
to BBEdit-Talk
On 01/13/2021, at 19:22, Bruce Van Allen <b...@cruzio.com> wrote:
I think people might be getting differing behavior because trying with different versions of BBEdit.

I’m running the latest beta (version 13.5.5 build 415089), and my “Process Lines Containing…” dialogue looks different from the image Christopher posted. And the regex ^\s*$ does NOT work. Nor does ^\h*\$ .

What versions are y’all using?



Hey Bruce,

I'm using BBEdit 12.6.7 (412120) on my Sierra Mac and BBEdit 13.5.5 on my Mojave Mac.

Both behave the same for me and delete “empty” lines with this pattern:


--
Best Regards,
Chris

Neil Faiman

unread,
Jan 13, 2021, 9:05:56 PM1/13/21
to BBEdit Talk Mailing List


On Jan 13, 2021, at 8:22 PM, Bruce Van Allen <b...@cruzio.com> wrote:

I think people might be getting differing behavior because trying with different versions of BBEdit.

I’m running the latest beta (version 13.5.5 build 415089), and my “Process Lines Containing…” dialogue looks different from the image Christopher posted. And the regex ^\s*$ does NOT work. Nor does ^\h*\$ .

What versions are y’all using?


BBEdit 13.5.5 (415089, 64-bit Intel, sandboxed)
macOS Mojave 10.14.6

and neither "^$" nor "^\h*$" nor "^\s*$" deletes blank lines for me.

Bruce Van Allen

unread,
Jan 13, 2021, 9:36:05 PM1/13/21
to BBEdit-Talk, sup...@barebones.com

On 01/13/2021, at 19:22, Bruce Van Allen <b...@cruzio.com <mailto:b...@cruzio.com>> wrote:

I think people might be getting differing behavior because trying with different versions of BBEdit.
I’m running the latest beta (version 13.5.5 build 415089), and my “Process Lines Containing…” dialogue looks different from the image Christopher posted. And the regex ^\s*$ does NOT work. Nor does ^\h*\$ .

What versions are y’all using?

On 13 Jan 2021, at 17:59, Christopher Stone wrote:

I'm using BBEdit 12.6.7 (412120) on my Sierra Mac and BBEdit 13.5.5 on my Mojave Mac.

Both behave the same for me and delete “empty” lines with this pattern:

[screenshot of dialogue with pattern ^\h*$]

On 13 Jan 2021, at 18:05, Neil Faiman wrote:

BBEdit 13.5.5 (415089, 64-bit Intel, sandboxed)
macOS Mojave 10.14.6

and neither "^$" nor "^\h*$" nor "^\s*$" deletes blank lines for me.

OK - I’m cc:ing this to support.

Best Regards,

  • Bruce
Reply all
Reply to author
Forward
0 new messages