I have a file called my_file.txt that contains the following strings:
tasmax_day_ACCESS_historical_r1i1p1f3_gn.nc
tasmax_day_EC-Earth3_historical_r1i1p1f1_gn.nc
tasmax_day_EC-Earth3_historical_r1i1p1f1_gr.nc
tasmax_day_EC-Earth3_historical_r1i1p1f3_gn.nc
tasmax_day_HadGEM-MM_historical_r1i1p1f1_gn.nc
tasmax_day_HadGEM-MM_historical_r1i1p1f1_gr.nc
tasmax_day_HadGEM-MM_historical_r3i1p1f1_gn.nc
tasmax_day_MIROC_historical_r1i1p1f1_gn.nc
tasmax_day_MIROC_historical_r2i1p1f1_gn.nc
I need to perform a unique of the substring starting with tasmax end ending in _historical where for each such substring I would keep only that line containing it that comes first in alphabetical order.
My expected output of my_file.txt is the following:
tasmax_day_ACCESS_historical_r1i1p1f3_gn.nc
tasmax_day_EC-Earth3_historical_r1i1p1f1_gn.nc
tasmax_day_HadGEM-MM_historical_r1i1p1f1_gn.nc
tasmax_day_MIROC_historical_r1i1p1f1_gn.nc
Thanks for any help.