Author Topic: Deleting all blank lines in a file  (Read 8206 times)

cdrdash

  • New Community Member
  • Posts: 1
  • Hero Points: 0
Deleting all blank lines in a file
« on: September 25, 2007, 06:41:36 pm »
Is there a simple way to delete all blank lines in a file with SlickEdit?

hs2

  • Senior Community Member
  • Posts: 2757
  • Hero Points: 291
Re: Deleting all blank lines in a file
« Reply #1 on: September 25, 2007, 07:19:42 pm »
Yes - e.g. by simply search'n replace them using a regex like that:
'c/^[ \t]*\n//@rp*' on SE cmdline.

HS2

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: Deleting all blank lines in a file
« Reply #2 on: September 26, 2007, 01:11:09 pm »
There is a ready-made command delete-blank-lines written for the Emacs emulation, but can be bound to a key in any emulation or used on the SlickEdit command-line any time.

hs2

  • Senior Community Member
  • Posts: 2757
  • Hero Points: 291
Re: Deleting all blank lines in a file
« Reply #3 on: September 26, 2007, 01:40:33 pm »
Good to know - that's much more convenient. Hopefully I'll remember next time I need it.
Although the regex method is more flexible (omit hidden lines, limit to selection etc.)...
Thanks Lee,
HS2

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: Deleting all blank lines in a file
« Reply #4 on: September 26, 2007, 01:57:09 pm »
Oops, just noticed the "all" in the Subject line.  delete-blank-lines only deletes all the blank lines from the current line.  It does not do the entire file, so the a regular expression search and replace is the right way to do the entire file.

bogedo

  • Community Member
  • Posts: 31
  • Hero Points: 0
Re: Deleting all blank lines in a file
« Reply #5 on: February 26, 2023, 07:02:51 pm »
aware that an old topic is being dug up but this is still relevant all these years later. hs2's solution still works but it would be great if we had a built in function to delete all the blank lines in a file.

Graeme

  • Senior Community Member
  • Posts: 2748
  • Hero Points: 340
Re: Deleting all blank lines in a file
« Reply #6 on: February 27, 2023, 05:50:13 am »
If you expect to be able to reverse the operation in one step then it's not trivial unless you do it by saving a copy of the file before you do the delete.  I can't imagine anyone wanting to delete all the blank lines from a software source file  -  is that what you want this for or is it some other kind of file?

Tim Kemp

  • Senior Community Member
  • Posts: 541
  • Hero Points: 92
Re: Deleting all blank lines in a file
« Reply #7 on: March 04, 2023, 05:12:01 am »
I've never needed to do it to a source code file, but I have done it regularly when I'm formatting data for a variety of things. Often the data ends up in a source code file.