小编Bre*_*ble的帖子

创建具有匹配(但不相同)结尾的文件夹列表

我有一个目录,其中包含以 .ctpre 或 .ctpost 结尾的文件夹(例如“15.ctpre”)以及其他文件/文件夹。我想制作一个列表,其中仅包含具有 pre 和 post 文件夹的主题,并且我只想保留匹配的主题 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
Run Code Online (Sandbox Code Playgroud)

有没有更有效的方法来做到这一点?

shell-script

3
推荐指数
1
解决办法
71
查看次数

标签 统计

shell-script ×1