Reputation: 3
Iam trying to get unique data from the file containing duplicates.
here is the file sample.txt with the data as below.
01|128
01|132
02|124
02|258
03|858
03|788
04|418
04|129
05|328
05|398
i want to get only unique data based on the column ie only one entry for 01|, 02|, 03|,04|,05|
grep -m1
grep: illegal option -- m
i tried using m1 option but it doesn't support
I/P:sample.txt
01|128
01|132
02|124
02|258
03|858
03|788
04|418
04|129
05|328
05|398
Expected O/P
01|128
02|124
03|858
04|418
05|328
Upvotes: 0
Views: 20
Reputation: 85767
That can be done with:
sort -nu
-n
says to use numeric comparison (so 01|...
will be treated as 1
, 02|...
as 2
, etc). -u
only outputs the first line of a run of equal elements.
Upvotes: 3