RSS Feed Subscribe to RSS Feed

 

Sublime notes

The following are some notes & examples of using Sublime Text for quick text editing, typically using regular expressions.

All the examples below typically start with:

  1. Go to the Find → Replace
    – or press ⌘ Cmd + Alt + F on Mac
  2. Select the ‘Regular expression‘ by clicking on the .* button in the – or press ⌘ Cmd + Alt + R on Mac

How to delete all lines starting with a number/digit

1. In the Find field, type in:

  • ^[[:digit:]].*

2. Leave the Replace field empty

3. Click on the Replace All button

 

How to delete empty lines

1. In the Find field, type in:

  • ^(\r|\n\r?) to delete empty lines including those with whitespace
  • ^\n to delete empty lines excluding those with whitespace

2. Leave the Replace field empty

3. Click on the Replace All button

Credit: https://www.shellhacks.com/sublime-text-remove-empty-lines/

How to replace new lines with tabs 

For example to make data spreadsheet-friendly.

1. In the Find field, type in:

  • \n

2. In the Replace field, put:

  • \t

3. Click on the Replace All button

The problem with this is that you will end up with everything on one line.

So you may need to tweak, e.g. if you can identify the characteristics of each new line, such as a it starts with a letter, and replace that with a new line…

F0r example (^[a-z]) -> \n\1 

(The \1 is a back reference to the previously found text)

 

 

Tags: , ,

Leave a Reply