Linux command uniq,sort
Use the following syntax:
uniq {file-name}
Here is a sample c file called hello.c:
#include < stdio.h>
void main()
{
printf("hello\n");
printf("hello\n");
}
When we execute the command
uniq hello.c the output is
#include< stdio.h>
void main(){ printf("hello\n");}
This will have one line and then remove the duplicate
To remove all the duplicates use -u option.
-u will remove all the duplicate entries
so
uniq hello.c will result#include< stdio.h>void main() {
printf("hello\n");}
The right method is sort the file first and then remove the duplicates.The syntax is sort {filename} | uniq -uWhen we execute the command
sort hello.c | uniq -uthe output is
{
}
#include< stdio.h>
void main()In both cases the original file is not modified
No comments:
Post a Comment