Issue
I have a file :
AX-172321889 4
AX-172321889 4
AX-172322243 2
AX-172322331 2
AX-172322347 2
AX-172322347 2
AX-172322347 2
AX-172322354 2
AX-172322383 2
AX-172322440 2
AX-172322719 7
I need to remove every duplicated or more lines. And not keeping one occurence for each of them. I know :
awk '!seen[$1]++'
or sort -t'-' -k1,2n | uniq
is pretty close of what I want, but this keeps one occurence.
I should get :
AX-172322243 2
AX-172322331 2
AX-172322354 2
AX-172322383 2
AX-172322440 2
AX-172322719 7
Solution
This might work for you (GNU uniq):
uniq -u file
Or if it just the first field use:
uniq -uw 12 file
Belt and braces:
sort file | uniq -uw 12
A GNU sed solution:
sed -E 'H;$!d;x;s/(\n\S+ )\S+(\1\S+)+//g;s/.//' file
Answered By - potong Answer Checked By - Clifford M. (WPSolving Volunteer)