你如何解析在bash的文件名? [英] How do you parse a filename in bash?

查看:108
本文介绍了你如何解析在bash的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个格式的文件名,如:

I have a filename in a format like:

系统源yyyymmdd.dat

我希望能够使用解析出文件名的不同位 - 作为分隔符

I'd like to be able to parse out the different bits of the filename using the "-" as a delimiter.

推荐答案

您可以使用剪切命令让每个3'场'的,例如:

You can use the cut command to get at each of the 3 'fields', e.g.:

$ echo "system-source-yyyymmdd.dat" | cut -d'-' -f2
source

- D指定分隔符,-f指定您需要的场数

"-d" specifies the delimiter, "-f" specifies the number of the field you require

这篇关于你如何解析在bash的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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