How can I use uniq on a certain field or what else could I use? If I want to use uniq on the second field and the output would remove one of the lines with a 5.
bob 5 hand
jane 3 leg
jon 4 head
chris 5 lungs
How can I use uniq on a certain field or what else could I use? If I want to use uniq on the second field and the output would remove one of the lines with a 5.
bob 5 hand
jane 3 leg
jon 4 head
chris 5 lungs
I added an extra line "joe 5 hand" to show that the uniq command can work; although not exactly what you are looking for.
I sorted on the 2nd key field, as uniq wants a sorted file
I then used the uniq command with the -f1 to skip over the first field
since there are two records with "*anything* 5 hand" only one was printed
> cat file92
bob 5 hand
jane 3 leg
jon 4 head
chris 5 lungs
joe 5 hand
> cat file92 | sort -k2 | uniq -f1
jane 3 leg
jon 4 head
bob 5 hand
chris 5 lungs
What you are looking for, I am not sure if it can be done this way. I would think using awk to be the best solution.