用awk删除多个文件扩展名呢? [英] Using Awk to remove one of multiple file extensions?

查看:85
本文介绍了用awk删除多个文件扩展名呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一些东西有关转换的文件,我试图找到一个shell命令删除原来的文件扩展名。
例如,如果我将一个名为 text.rtf 文件,它会转换成 text.rtf.mobi 。我想使用的东西去掉.RTF(或任何其他分机),所以它只是 text.mobi

我一直在玩的awk和sed但我无法得到任何工作。我不知道如何得到它拿起两个原分机和.mobi域名,而只是删除原来的扩展。

有点关系,我应该在哪里将要收拾正则表达式,实际上理解它,而不是仅仅巨量谷歌搜索?谢谢你。

修改:我是在原来的职位有点不清楚,所以让我澄清一下。 shell命令我需要的是去除在转换后的文件中的原始扩展名,如text.ANYTHING.mobi。很抱歉的混乱。


解决方案

 在*的.mobi˚F
  做
    MV $ F $(回声$ F |切-d -f1'。')的.mobi
  DONE

I'm working on some stuff related to converting files, and I'm trying to find a shell command to remove the original file extension. For example, if I convert a file called text.rtf, it will be converted into text.rtf.mobi. I'd like to use something to remove the .rtf (or any other extension) so it's only text.mobi.

I've been playing with awk and sed but I couldn't get anything to work. I'm not sure how to get it to pick up both the original extension and the .mobi, but only remove the original extension.

Somewhat related, where should I be going to pick up regex and actually understand it instead of just immense amounts of Googling? Thanks.

EDIT: I was a little unclear in the original post so let me clarify. The shell command I need is for removing the original extension in a converted file, such as text.ANYTHING.mobi. Sorry about the confusion.

解决方案

for f in *.mobi
  do
    mv $f $(echo $f | cut -d'.' -f1).mobi
  done

这篇关于用awk删除多个文件扩展名呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆