Suppose you have a file seperated with a delimiter like tab or comma and you want to swap them manually it would take so much time if the file is huge. But if you want to do it using just a single command it would take 5 seconds.
Here is how it is done.
- Open the file to be edited using following command.
- vim file.txt
- Then enter the following substitution commnad.
- %s/\(.*\)\t(.*\)/\2\t\1/g
- That’s it you have swapped two columns.
- Now just save the file and quit vim using :wq
There is a video of the same below