Sometimes the simplest thing is really taken for granted and we take the long route to do the simplest thing. We received a CSV with thousands of ID numbers that will be used to update a database table. The data would look like the following:
87295 86719 31695 94836 17957 69783 57168 96874 12853 92816 ... [deleted for brevity] ...
The goal is just to add a comma at the end of each line so it can be used to update data in a database table.
In the past, we would probably write a macro module in Excel, but other than a security risk, it’s overcomplicating a simple task.
Using either Visual Studio Code or Sublime Text, we can accomplish this task in a matter of seconds. No writing macros required.
1. Use the Search and Replace Control
This works the same way in both Visual Studio Code and Sublime Text. The only difference is the shortcuts between PC and Mac.
PC
- Press CTRL+H for Replace.
- Type in $ in Find, and , in Replace.
- Make sure Regular Expression is turned on (ALT+R)
- Replace All by pressing CTRL+ALT+ENTER.
Mac
- Press Option+Command+F for Replace.
- Type in $ in Find, and , in Replace.
- Make sure Regular Expression is turned on (Option+Command+R)
- Replace All by pressing Option+Command+ENTER.
2. Use Multi-Line Editing
Visual Studio Code
- Select all by pressing CTRL+A (or Command+A for Mac).
- From Selection, choose Add Cursors to Line Ends by pressing SHIFT+ALT+I (or SHIFT+OPTION+I).
- Type the Comma character.
Sublime Text
- Select all by pressing CTRL+A (or Command+A for Mac).
- From Selection, choose Split into Lines by pressing CTRL+SHIFT+L (or COMMAND+SHIFT+L).
- Move the cursors at the end of lines by pressing End on Windows or Right Arrow on macOS.
- Type the Comma character.
Whatever method you use, the end result will look like the following:
Further Reading
How to Reassign Shortcut Key for Column Selection in Visual Studio Code
How to Reassign Column Selection Shortcut Keys in Sublime Text
Adding Comma to Each Line Using Sublime Text 2
How to Open Visual Studio Code from command line macOS