Bash,从字符串中用点字符剪切单词

标签 bash shell awk sed grep

我有一个字符串:

Log for: squid.log.2017.11.13

我需要删除 squid.log. 以便我看到:

Log for: 2017.11.13

我尝试剪切

echo "Log for: squid.log.2017.11.13" | cut -d'.' -f3-5

但我最终得到了:

2017.11.13

我怎样才能得到我想要的结果?

最佳答案

您可以使用sed 删除不需要的部分:

echo "Log for: squid.log.2017.11.13" | sed 's/squid\.log\.//'

关于Bash,从字符串中用点字符剪切单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47295992/

相关文章:

linux - 为什么不取命令行的第一行作为输出

linux - 使用awk从文本文件中提取数据

linux - if 语句中的未知错误

bash - 我怎样才能剪掉(1)驼峰字?

linux - shell脚本匹配来自另一个文本文件的数据

bash - 如何将子 shell 的输出文件描述符重定向到父 shell 中的输入文件描述符?

python - gunicorn - 如果从 shell 脚本执行则不获取配置文件

bash - 如何用另一个文件的映射值替换 csv 文件中的第 n 个字段?

git - 登录目前与 git bash/cygwin 不兼容

bash - 识别带引号空格的列