Bash脚本删除目录中多个文件名末尾的'x'字符数量?
16lz
2021-01-22
I have a list of file names in a directory (/path/to/local
). I would like to remove a certain number of characters from all of those filenames.
我在目录中有一个文件名列表(/ path / to / local)。我想从所有这些文件名中删除一定数量的字符。
Example filenames:
iso1111_plane001_00321.moc1
iso1111_plane002_00321.moc1
iso2222_plane001_00123.moc1
In every filename I wish to remove the last 5 characters before the file extension.
在每个文件名中,我希望删除文件扩展名之前的最后5个字符。
For example:
iso1111_plane001_.moc1
iso1111_plane002_.moc1
iso2222_plane001_.moc1
I believe this can be done using sed
, but I cannot determine the exact coding. Something like...
我相信这可以使用sed完成,但我无法确定确切的编码。就像是...
for filename in /path/to/local/*.moc1; do
mv $filname $(echo $filename | sed -e 's/.....^//');
done
...but that does not work. Sorry if I butchered the sed
options, I do not have much experience with it.
......但那不起作用。对不起,如果我屠杀了sed选项,我没有太多的经验。
3 个解决方案
#1
6
mv $filname $(echo $filename | sed -e 's/.....\.moc1$//');
or
echo ${filename%%?????.moc1}.moc1
%% is a bash internal operator...
%%是一个bash内部运算符......
更多相关文章
- 字符串处理函数strcat和strtok
- 对linux字符设备的理解(整体架构)
- gdb捕获syscall条件和字符串比较
- Linux C 字符串输入函数 gets()、fgets()、scanf() 详解
- Linux生成随机字符串
- 关于mysql jsp字符编码的问题解决
- 如何将“u00e9”转换为一个utf8字符,在mysql或php中?
- 【整理】更改MSSQL默认字符集
- 5 - SQL Server 2008 之 四则运算、比较运算、逻辑运算及字符连