sWarren :
I have multiple urls in a file like this:
https://private/report-artifact/dsop-pipeline-artifacts/container-scan-reports/anchore/enterprise/enterprise/0.6.1/2020-02-08T004236.092_2801/enterprise-0.6.1.tar
https://private/report-artifact/dsop-pipeline-artifacts/container-scan-reports/atlassian/bamboo-data-center/bamboo-agent/6.10.4/2019-12-17T185400.126_2118/bambo.tar
...
I want to them to be sorted A-Z according to the last value, ie:
https://private/report-artifact/dsop-pipeline-artifacts/container-scan-reports/atlassian/bamboo-data-center/bamboo-agent/6.10.4/2019-12-17T185400.126_2118/bambo.tar
https://private/report-artifact/dsop-pipeline-artifacts/container-scan-reports/anchore/enterprise/enterprise/0.6.1/2020-02-08T004236.092_2801/enterprise-0.6.1.tar
...
I can get the sed
value of the last parameter with sed 's|.*/||'
, which gives me the A-Z pattern I am looking for:
bambo.tar
enterprise-0.6.1.tar
But not sure how I can "sort" the entire url line like I want?
Barmar :
Duplicate the filename as an additional field, sort by that field, then remove the extra field.
sed 's/[^/]*$/& &/' | sort -k 2 | cut -d' ' -f1