How to Remove Duplicate lines from Unix vi Editor file


Sometimes we have the requirement for removing the duplicate lines from the text file. For that we can easily use vi to remove the duplicate lines instead of using any other scripts or tools. Here are the options to remove the duplicate lines from the vi file.

Open the vi file and in command mode (press esc) give the command :sort u
The above command will sort the file which will give the file with duplicate lines closer. Now you can remove the duplicate lines.

1G #### Go to first line of the file
!Gsort ## Sort the file from the first line
1G #### Again go to first line
!Guniq ## Remove duplicate with uniq command.



Post a Comment Copyright 2011-17 All Rights Reserved | Site Map | Contact | Disclaimer | Google