shell - 多个“。”的外壳文件扩展名
问题描述
我需要提取目录中文件的文件扩展名,但是文件格式如下,
ab10001i.39400.8163.txt
ab10001i.39400.0433.txt
ab10001i.39400.24433.txt
ab10001i.39400.90631.TXT
我尝试了以下脚本,但没有给我预期的结果..有什么建议吗?谢谢你!!
for file in "$SEARCH_DIR"/*; do
clmFile=`basename "$file"`
lastpart=``echo -n ${clmFile%.*} | tail -c4``
echo "TEST THIS THIS " $lastpart
if [ ${extension} == "TXT" ]; then
echo "TXT FILE"
elif [ ${extension} == "txt" ]; then
echo "txt FILE"
fi
done
解决方案
找到了解决办法。。
lastpart=`echo -n ${clmFile%} | tail -c4
这将提取如下输出
txt
txt
txt
TXT
我的输入文件
ab10001i.39400.8163.txt
ab10001i.39400.0433.txt
ab10001i.39400.24433.txt
ab10001i.39400.90631.TXT
这是一个好的脚本练习吗?还有其他建议或建议吗?
推荐阅读
- python - 具有原始二进制数据的 np.ndarray 上的 Python3 管道 I/O 失败
- javascript - 在php中使用foreach选择框时如何使用java脚本选择选择框元素
- angular - http://localhost:8000/api/... 的 Http 失败响应 500 角度 5 中的内部服务器错误
- ibm-cloud-infrastructure - SoftLayer:softlayer 资源 ID 是否因订单而异?
- php - 无法在php mysql的表中插入记录
- javascript - 如果第二个项目的 package.json 不在项目的根目录中,如何在 package.json 中添加 github 依赖项
- python - 如何将自定义张量流模型与 CV2 DNN 模块一起使用?
- jsp - 在jsp中包含jsp,单击jsp中的按钮时如何删除包含jsp?
- c++ - QImage:加载图像时自动检测格式
- python - 如何使用 Flask 会话在 Twilio 中分离应用程序用户之间的会话?