linux - 在文件扩展名后获取一个数字
问题描述
我有千兆字节的文件,具有以下命名约定:
H__Flights_SCP_Log_Analysis_Log_Store_Extracted_File_Store_Aircraft_023_Logs_06Apr2021_164418_dtd_slotb_MDN_Gateway_Logs_audit_audit.log.1
最后的数字(1
)很重要,我需要抓住它。目前我的代码如下所示:
#!/bin/bash
#this grabs all the log files in the folder that will be converted and places it in a variable
files=$(find ./ -name "*.log*")
#I iterate through each file in files to convert each one
for file in $files
do
#this grabs the file name except the file extension and places it in a variable
name=${file%.*}
#this converts the file and places it in a file with the same name plus a csv extension
ausearch -if "file" --format csv>>$name.csv
done
这可以很好地转换日志并命名它们,只是它不获取文件扩展名末尾的数字。我怎么能抓住它?
解决方案
继续使用 OP 当前使用参数替换...
$ file='H__Flights_SCP_Log_Analysis_Log_Store_Extracted_File_Store_Aircraft_023_Logs_06Apr2021_164418_dtd_slotb_MDN_Gateway_Logs_audit_audit.log.1'
$ mynum="${file##*.}"
$ echo "${mynum}"
1
# or
$ mynum="${file//*./}"
$ echo "${mynum}"
1
推荐阅读
- python - Python:当第一列并不总是相等时,抓取表/获取特定列
- php - laravel 链接 isForceDeleting() 事件(在观察者上)
- typo3 - 将根模板外包到 TYPO3 扩展中
- java - 理解计算幂集的递归流程
- css - CSS-styles do not load when using Vuetify Automatic a la Carte
- linux - How to make a perfect dead symbolic link
- java - The type CucumberOptions is deprecated how can i resolve the issue
- ruby-on-rails - Rails 6:远程表单:true和Turbolinks在重定向后不显示flash
- sql - 正则表达式只允许选择和禁止其他操作,即插入删除刷新
- angular - Bootstrap Modal 不显示正确的数据