Unix的削减除了最后两个记号 [英] Unix cut except last two tokens

查看:126
本文介绍了Unix的削减除了最后两个记号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图分析在特定目录中的文件名。文件名是格式:

I'm trying to parse file names in specific directory. Filenames are of format:

token1_token2_token3_token(N-1)_token(N).sh

我需要削减使用分隔符令牌'_',以及需要采取的字符串除了最后两个标记。在上述examlpe输出应为 token1_token2_token3

I need to cut the tokens using delimiter '_', and need to take string except the last two tokens. In above examlpe output should be token1_token2_token3.

令牌的数目不是固定的。我试着 -f#做到这一点 - 切选项命令,但没有找到任何解决办法。任何想法?

The number of tokens is not fixed. I've tried to do it with -f#- option of cut command, but did not find any solution. Any ideas?

推荐答案

通过切口:

$ echo t1_t2_t3_tn1_tn2.sh | rev | cut -d_ -f3- | rev
t1_t2_t3

这篇关于Unix的削减除了最后两个记号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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