AWKを使用したタイムスタンプによる異なる重複項目のフィルタリング

AWKを使用したタイムスタンプによる異なる重複項目のフィルタリング

以下のようにタイムスタンプでソートされたファイルのリストを提供します。各ファイルの最後の項目(各ファイルの一番下のファイル)を検索しようとしています。

たとえば、

archive-daily/document-sell-report-2022-07-12-23-21-02.html
archive-daily/document-sell-report-2022-07-13-23-15-34.html
archive-daily/document-loan-report-2022-07-18-05-12-16.html
archive-daily/document-loan-report-2022-07-18-17-07-26.html
archive-daily/document-deb-report-2022-07-18-13-17-40.html
archive-daily/document-deb-report-2022-07-18-10-04-21.html

次のようになります。

archive-daily/document-sell-report-2022-07-13-23-15-34.html
archive-daily/document-loan-report-2022-07-18-17-07-26.html
archive-daily/document-deb-report-2022-07-18-10-04-21.html

これを達成するためにawkまたは他のコマンドを使用できますか?よろしくお願いします。

ベストアンサー1

$ tac file | awk '!seen[substr($0,1,length()-25)]++'
archive-daily/document-deb-report-2022-07-18-10-04-21.html
archive-daily/document-loan-report-2022-07-18-17-07-26.html
archive-daily/document-sell-report-2022-07-13-23-15-34.html

おすすめ記事