Wednesday 24 October 2012

Linux for you Admin Tips: 7

Linux for you Admin Tips:1
Linux for you Admin Tips:2
Linux for you Admin Tips:3
Linux for you Admin Tips:4
Linux for you Admin Tips:5
Linux for you Admin Tips:6
Linux for you Admin Tips:8

How to print only the duplicate values from a text file?

Suppose there is a column of numeric values like following:
File1:
1 2
3
3
3
4
4
4
5
6
I want the output:
3  4

Ans::
You can use uniq(1) for this:
uniq -d file1.txt
This will print out the duplicates only.
sankar@new-host shell script]$ uniq -d file1.txt
+ uniq -d uniq1.txt
2
4
6
7
2. [sankar@new-host shell script]$ cat uniq1.txt  | uniq -c | awk '$1 > 1 { print $2 }'
+ uniq -c
+ awk '$1 > 1 { print $2 }'
+ cat uniq1.txt
2
4
6
7

No comments:

Post a Comment