Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 Bash 脚本非常陌生,并且想针对我遇到的以下问题对其进行测试。我目前在表单中的目录中有很多文件
V3_August_'day'_0_'simulations'.pickle
where'day'和'simulations'表示针对不同文件而变化的变量。我想将这些转换成表格
'day'
'simulations'
V3_2012_8_'day+1'_0_'simulations'.pickle
遍历这些文件并根据需要重命名它们的脚本是什么?
纯基于 bash 的解决方案:
for x in *.pickle; do [[ $x =~ ^([^_]+_[^_]+_)([^_]+)(_.+)$ ]] && mv "$x" \ "${BASH_REMATCH[1]}$((${BASH_REMATCH[2]} + 1))${BASH_REMATCH[3]}" done