Bash/从字符串中获取子字符串

标签 bash sh

<分区>

我运行下一个:

 find . -type f -printf '%T@ %p\n' | sort -n | tail -1

下一个返回给我:

1376221215.000000000 ./Rev.12345/run.exe

我只想获取 12345 号码。我应该使用哪个命令(我尝试使用 cut 命令,但没有成功)?

最佳答案

您可以将输出通过管道传输到 sed:

... | sed 's/.*Rev\.\([0-9]*\).*/\1/'

关于Bash/从字符串中获取子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18170488/

相关文章:

json - Shell 脚本空格转义

linux - Awk 不能在 bash 脚本中工作

bash - "correct"的最简单方法是意外使用 mv 而不是 hg mv?

bash - 'if -e' 和 'if -f' 之间的区别

sh - Cloudflare DDNS 使用 API v4 重复 sh 脚本,在单个 sh 脚本中有多个 A 记录,但失败

linux - 巴什 |将文件排序到子目录

sh - typeset -i2 var=2#0 在 bash/korn shell 中意味着什么?

shell - tomcat 在路径 "webapps/"下发布了两个项目

java - 我应该使用哪个 Eclipse 来使用 Java、C、Bash 和 Perl?

linux - 如何在脚本中包含和排除字符串