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
![](https://ik.imagekit.io/dumani/My_Blog/image_rh2Ko9HNEV.png?updatedAt=1640667098162)
Find and replace text in multiple files
- In Visual Studio Code, right click on a folder and click “Find in Folder…”
![](https://ik.imagekit.io/dumani/My_Blog/image_sprZ2s1a5l44.png?updatedAt=1640711824530)
- 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.
![](https://ik.imagekit.io/dumani/My_Blog/image_H64Awt1wa.png?updatedAt=1640711969242)
If you click on a preview in search results, you can can the a side-by-side view of the change in each file.
![](https://ik.imagekit.io/dumani/My_Blog/image_kjwtuOyMxaR.png?updatedAt=1640712180268)
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”
![](https://ik.imagekit.io/dumani/My_Blog/image_qQLIAQTk2mjg.png?updatedAt=1640713168106)
Get unique / remove duplicate lines in a list of text
![](https://ik.imagekit.io/dumani/My_Blog/image_HXtgNPLp7U.png?updatedAt=1640713768608)
- Select the list of text
- Click View > Command Paletter
- Click one of the unique sort options
![](https://ik.imagekit.io/dumani/My_Blog/image_WWUz6H3HTd4U.png?updatedAt=1640713861421)
![](https://ik.imagekit.io/dumani/My_Blog/image_SpSm1kdBCe.png?updatedAt=1640713904468)
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
![](https://ik.imagekit.io/dumani/My_Blog/image_FHaVxihwT.png?updatedAt=1640713302569)
- You can then start typing to replace the text or copy the text to the clipboard
![](https://ik.imagekit.io/dumani/My_Blog/image_iSIu0XhJ7.png?updatedAt=1640713552918)
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.
![](https://ik.imagekit.io/dumani/My_Blog/image_cJVasjXZG-.png?updatedAt=1640712587812)
![](https://ik.imagekit.io/dumani/My_Blog/image_CYIzcw1YJrk.png?updatedAt=1640712806835)
- Right click on the highlighted text and click “Copy”
![](https://ik.imagekit.io/dumani/My_Blog/image_kGumXo9qjo.png?updatedAt=1640712888898)
- You could then paste the copied text in a new file
![](https://ik.imagekit.io/dumani/My_Blog/image_yThQ6LgOd6d.png?updatedAt=1640712975198)
Add text to the beginning of each line of text
- Click Edit > Replace
- Use the following regex search
![](https://ik.imagekit.io/dumani/My_Blog/image_nQOrGQbX2wM.png?updatedAt=1640714143063)
![](https://ik.imagekit.io/dumani/My_Blog/image_-6ZLUdGwFmE.png?updatedAt=1640714221458)
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”
![](https://ik.imagekit.io/dumani/My_Blog/image_nlDIBz0Xqft.png?updatedAt=1640717878980)
You will then see a nice diff between the two files.
![](https://ik.imagekit.io/dumani/My_Blog/image_CSvQfIWwf.png?updatedAt=1640717958466)
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.
![](https://ik.imagekit.io/dumani/My_Blog/image_ioLXlPahoMB.png?updatedAt=1640718145599)
You can then click Export > File Diffs > Traditional > In Text > To Clipboard to copy the diff to your clipboard.
![](https://ik.imagekit.io/dumani/My_Blog/image_Oj8qmc82B.png?updatedAt=1640718241049)
You can then paste the diff in a text editor like Visual Studio Code and extract only the text you are interested in.
![](https://ik.imagekit.io/dumani/My_Blog/image_7kBRt8g6sh.png?updatedAt=1640718327815)
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.
![](https://ik.imagekit.io/dumani/My_Blog/image_bp_cn2zXn.png?updatedAt=1640718673104)