在Linux bash中使用正则表达式更改输出文件名 [英] Use regular expression in linux bash to change output filename
本文介绍了在Linux bash中使用正则表达式更改输出文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经下载了一些epub文件,我需要再次将它们转换为epub,以便我的电子书阅读器可以读取它们.
I have downloaded a few epub files and I need to convert them to epub again so that my ebook reader can read them.
我可以使用R相当容易地进行批量转换,如下所示:
I can do conversion in batch fairly easily using R as below:
setwd('~/Downloads/pubmed')
epub.files = list.files('./',full.names = TRUE,pattern = 'epub$')
for (loop in (1:length(epub.files))) {
command = paste('ebook-convert ',
epub.files[loop],
gsub('\\.epub','.mod.epub',epub.files[loop]))
system(command)
}
但是我不知道如何使用linux bash做到这一点,我也不知道:i)如何在for循环内分配变量,以及ii)如何使用正则表达式替换bash中的字符串.
But I don't know how to do it using linux bash, I don't know: i) how to assign a variable within a for-loop, and ii) how to use regular expression to replace string in bash.
任何人都可以帮忙吗?谢谢.
Can anyone help? Thanks.
推荐答案
您还可以使用 bash的参数替换:
for i in *.epub; do
ebook-convert ${i} ${i/%.epub/.mod.epub}
done
这篇关于在Linux bash中使用正则表达式更改输出文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文