一致する(しかし同じではない)エンディングを持つフォルダのリストを作成します。

一致する(しかし同じではない)エンディングを持つフォルダのリストを作成します。

.ctpre または .ctpost (例: "15.ctpre") で終わるフォルダーと、その他のファイル/フォルダーを含むディレクトリがあります。フロントフォルダとリアフォルダを含むテーマのみを含むリストを作成したいのですが、一致するテーマID(「15」など)のみを保持したいと思います。

これは私の現在のコードです。

#Make a list of folders that include .ct
find *.ct* -maxdepth 0 -fprint temp1
#In this list, remove the .ctpre and .ctpost extensions
sed 's/.ctpre//' temp1 > temp2
sed 's/.ctpost//' temp2 > temp3
#Sort the list
sort temp3 > temp4
#Print/save only duplicate entries on the list
uniq -d temp4 > sub_list
#Delete temp files
rm temp1 | rm temp2 | rm temp3 | rm temp4

これを行うより効率的な方法はありますか?

ベストアンサー1

すべてのスクリプトは1行にあります

for file in *.ctp{ost,re} ; do echo ${file%.*} ; done | sort | uniq -d > sub_list

または(ありがとうドルベンコメント用)

for f in *.ctpre; do [ -d ${f%.*}.ctpost ] && echo ${f%.*} ; done > sub_list

おすすめ記事