Share & learn

Through Innovative Digital Library

How to remove duplicate lines from file by using sed command?

How to remove duplicate lines from file by using sed command?
 



Answers

Posted by chandu on December 11th 2017 08:30 AM

If you want to delete the duplicate lines in file, use the sed command to delete the duplicate lines. First create one file and add duplicate data.

# cat file

Posted by chandu on December 11th 2017 08:34 AM

The above screen there is duplicate lines, so now i want to remove duplicate lines, we can remove the duplicate data by using following sed command. If you run the command with file name it will delete the duplicate lines.

# sed '$!N; /^\(.*\)\n\1$/!P; D' file
Answer Question

Your email address will not be published. Required fields are marked *

  • Minimum 20 character
ZKVR

related questions

Most liked questions

Most answered questions

Login
ZKVR Refresh
Register
ZKVR Refresh
Forgot password
Ask a Question
Minimum 20 character
Minimum 20 character
Reply
Minimum 20 character
ZKVR Refresh