-1

The text file I am using contains top-selling songs. It is structured as follows:

Single,Artist,Record label,Released,Chart,Traditional sales peak,

some example lines:

Imagine,John Lennon,Apple,Oct-75,1,1714351
Uptown Funk,Mark Ronson featuring Bruno Mars,RCA,Dec-14,1,1647310
Wonderwall,Oasis,Creation,Oct-95,2,1502270

I am trying to find which what year has the hits in the file.

I am aware that there are more efficient commands I can use such as awk, however I need to complete this using grep.

Any help or guidance is appreciated :)

  • 1
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Nov 15 '22 at 21:52

1 Answers1

1

Here we go:

 $ grep -oP '^([^,]+,){3}\w+-\K\d+' file | sort | uniq -c
  1 14
  1 75
  1 95

But as far as we don't have the century, there's some weird results needing a complicated process/heuristic

Gilles Quénot
  • 31,569
  • 7
  • 64
  • 82