Table of contents
- Find and replace text in a single text file
- Find and replace text in multiple files
- Find and replace multiple regexes in all files in a folder recursively
- Sort a list of text
- Get unique / remove duplicate lines in a list of text
- Select a column of text
- Find text in a single file and copy all matches to the clipboard
- Add text to the beginning of each line of text
- Copy differences (diff) between two files
- Rename multiple filenames in multiple folders
The instructions below use Visual Studio Code unless stated otherwise.
Find and replace text in a single text file
- Open the text file in Visual Studio Code
- Click Edit > Find or Edit > Replace
- Enter your search term and replace term
- Use optional options like
- case senstive match
- match whole word
- regular expression
- preserve case
- replace first match
- replace all matches at once
- find in selection
Find and replace text in multiple files
- In Visual Studio Code, right click on a folder and click “Find in Folder…”
- Enter your search term and replace term
- Use optional options like
- case senstive match
- match whole word
- regular expression
- preserve case
- In the search results, you will see a preview of the text change.
If you click on a preview in search results, you can can the a side-by-side view of the change in each file.
Find and replace multiple regexes in all files in a folder recursively
Modify this JavaScript and run using NodeJS.
Sort a list of text
- Select all the text to sort
- Right click on the selection and click “Sort lines”
Get unique / remove duplicate lines in a list of text
- Select the list of text
- Click View > Command Paletter
- Click one of the unique sort options
Select a column of text
- Put the cursor at one corner of the column of text you want to select
- On Windows, click and hold “Shift” + “Alt” keys and drag the cursor to the opposite corner of the column of text you want to select
- You can then start typing to replace the text or copy the text to the clipboard
Find text in a single file and copy all matches to the clipboard
- Open the text in Visual Studio Code
- Click Edit > Find
- Enter a search term
- Click Selection > Select All Occurrences
All matches will be highlighted. Notice the different highlight color in the two screenshots below.
- Right click on the highlighted text and click “Copy”
- You could then paste the copied text in a new file
Add text to the beginning of each line of text
- Click Edit > Replace
- Use the following regex search
Copy differences (diff) between two files
Let’s say you have two files and you want to get only the differences between the two. Visual Studio Code will show you a diff between two files as follows:
- Open both files
- Select both files in the OPEN EDITORS section
- Right click and click “Compare Selected”
You will then see a nice diff between the two files.
But, you won’t be able to copy only the changed lines or export the diff. On Windows, you can use a tool called DiffMerge by SourceGear. If you open both files, you’ll see a similar view.
You can then click Export > File Diffs > Traditional > In Text > To Clipboard to copy the diff to your clipboard.
You can then paste the diff in a text editor like Visual Studio Code and extract only the text you are interested in.
Rename multiple filenames in multiple folders
Let’s say you have many files and you want to rename the filenames all at once. For this, I find it easy to use a tool like Rename Expert. For example, in the screenshot below, I did the following:
- Added all files the filenames of which I want to rename
- Under “Actions”, chose the actions I want done. In this case, I did 2 actions:
- Replace (to replace the first character of each filename with an underscore)
- Edit file extension (to change the file extension from php to jpg)
- Previewed the changes and resolve any conflicts
- Clicked the Apply button to run the batch renaming of files.