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内部运算符......

更多相关文章

  1. 字符串处理函数strcat和strtok
  2. 对linux字符设备的理解(整体架构)
  3. gdb捕获syscall条件和字符串比较
  4. Linux C 字符串输入函数 gets()、fgets()、scanf() 详解
  5. Linux生成随机字符串
  6. 关于mysql jsp字符编码的问题解决
  7. 如何将“u00e9”转换为一个utf8字符,在mysql或php中?
  8. 【整理】更改MSSQL默认字符集
  9. 5 - SQL Server 2008 之 四则运算、比较运算、逻辑运算及字符连

随机推荐

  1. 开源项目Html Agility Pack实现快速解析H
  2. C 实现HTML5服务时,遇到握手状态的判断问
  3. 100%高度分区内显示:表格单元分区
  4. 我使用生成html文件的python制作了一个脚
  5. HTML代码格式化工具
  6. html5 canvas实例 绘制变形图形 径向渐变
  7. chtmlview中实现IDownloadManager时,创建C
  8. 广州朋友注意“蓝&白”快餐店:前客剩粥加
  9. 访问Java Servlet中的JavaScript表DOM
  10. 浮动到页面底部的可变高度页脚的CSS(不是