-1

How can I grep exact years in my file which contains world champions from years 1950-2000 but I want only years 1950/60/70/80/90/00? Thank you so much

closed as unclear what you're asking by Jeff Schaller, HalosGhost, techraf, sam, countermode Nov 15 '16 at 6:42

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

3
grep -E "19[5-9]0|2000" 

man grep:

   -E, --extended-regexp
          Interpret PATTERN as an extended regular  expression  (ERE,  see
          below).
0

Another two solutions:

  1. these years ends with 0, so you can call it like: grep "0$"
  2. numbers are divisible by 10: awk '{ if ($1 % 10 == 0) {print} }'
  • Your grep assumes the year to be at the end of the line and your awk for it to be in the first column - this might be too restrictive and is a bit contradictory in itself. – Fiximan Nov 15 '16 at 8:42
  • I'm sure it's good enough for the question above - there are just years specified, nothing more :) To be honest, if the input looks like 1999 some string 1950 yay another string, than any grep is useful there and one have to use awk anyway.I believe in people that they think before copy, paste and run :) – stderr Nov 15 '16 at 10:51
  • I'm not even blaming you for OP's insufficient input/output samples, yet if someone else stumbles across, it might be misinterpreted as a rather universal answer. And for that last point ... apart from recklessness, someone not familiar with PCRE or even basics of it might not know why things don't work out. It's about the universal approach of the whole Q&A system here. – Fiximan Nov 15 '16 at 18:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.