-3

I have a file with 7 fields separated with a :. In field 4 it has the group number. I want to display the group numbers within 0-1000. If there is a duplicate, I only want to print one copy of it along with the other group numbers that don't have a duplicate.

I have to use grep, awk, sort and uniq.

I don't know the first place to start. Can someone please help me?

E. Reyes
  • 29
  • 1
  • 7
  • 1
    Start with a file with 7 fields separated with a whitespace and use awk to print only column 4. – Cyrus Mar 25 '16 at 20:59

1 Answers1

1

awk to the rescue!

$ awk -F: '$4>=0 && $4<=1000 && !a[$4]++' file 

conditions are trivial, the array indexed by $4 will have nonzero value for the duplicates and not printed, only the first value of duplicates will have zero (before the ++ increment) value and printed.

karakfa
  • 66,216
  • 7
  • 41
  • 56