I have the following command:

find /home/cas/plex-media/series/ -type f -name '*.srt' | grep -v .en.srt

Which will find all .srt files, that are not .en.srt in the directory and subdirectories of series.

This will give me a list that could look like this:

/home/cas/plex-media/series/Scorpion/Season 4/Scorpion - S04E06 - Queen Scary.srt
/home/cas/plex-media/series/Scorpion/Season 4/Scorpion - S04E03 - Grow a Deer, A Female Deer.srt
/home/cas/plex-media/series/Devs/Season 1/Devs - S01E03 - Episode 3.srt
/home/cas/plex-media/series/Modern Family/Season 8/Modern Family - S08E21 - Alone Time.srt

This is a simplified version. There could be 5 or 300 outputs, where there could be 8 or 50 times Scorpion for example. The output varies very much.

I trying to find a command (that I could pipe behind the original command), that will be give me the result:

Scorpion, Devs, Modern Family

And not:

Scorpion, Scorpion, Scorpion, Scorpion, Devs, Devs, Modern Family, Modern Family, Modern Family, 
Modern Family, Modern Family, Modern Family, etc.. 

You get the idea. For every show, one output. Not for every file.

It can be in another layout. It doesn't really matter (altough I'd prefer the layout above).

I've been trying around with grep but I just can't do it. So i'm basically asking: Do you have an idea how I could get the output above?


  • Can you rely on a consistent delimiter between the series title and the remainder of the filename? In your examples, it is mostly ` - ` (space-hyphen-space) but in the case of Devs it is just - (hyphen-space). What cases should we expect? Dec 23, 2020 at 15:29
  • @steeldriver "Devs- " was a typo. Every path will be the following: /home/cas/plex-media/series/[Series title]/Season [Season number]/[Series title] - S[Season number]E[Episode number] - [Episode title].srt. Every file is named in this way. Spaces and hyphen's are all on the same place and in the same order as seen above.
    – Cas
    Dec 23, 2020 at 15:34

1 Answer 1


Assuming that the delimiter between the series title and the remainder of the filename is a consistent space-hyphen-space, you could do something like this with awk:

find . -type f -name '*.srt' ! -name '*.en.srt' -printf '%f\0' | 
  awk -v RS='\0' -F ' - ' '!seen[$1]++{print $1}' | paste -sd,

The !seen[$1] construct de-duplicates the results. The final paste command turns the output from a newline-delimited list to a comma-delimited list.

  • It works perfectly. Thanks! I've noticed that in quite alot of situations with naming and grepping strings, awk comes to the rescue. So I might go look into that awk more... Thanks!
    – Cas
    Dec 23, 2020 at 15:47
  • @Cas with the info, you may try to parse the [Series title] on the directory. I.e. if it is better formatted.
    – user986805
    Dec 23, 2020 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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