regex - 在bash中删除字符串的一部分
问题描述
我如何refs/heads/
从铰孔部分中取出部分refs/heads/hotfix/sub_pag/105
并返回hotfix/sub_page/105
?
解决方案
您可以使用cut
:
echo refs/heads/hotfix/sub_pag/105 | cut -d/ -f3-
-d
指定分隔符,/
在这种情况下-f
指定要保留的列(字段)。我们想要从第 3 列开始的所有内容。
或者,使用变量和参数替换:
x=refs/heads/hotfix/sub_pag/105
echo ${x#refs/heads/}
#
从变量值的开头删除字符串。
推荐阅读
- sql - 如何计算前 X% 的观看者观看了 50% 的观看次数
- regex - 根据第一个目录重定向
- python - 如何在 python 中使用配置文件组织单元测试?
- angular - 如何在 mat-table Angular 9 的每一行中添加一个按钮?
- python - 使用 pyodbc 连接到 microsoft sql db
- android - 需要alarmManager 或workManager?
- next.js - Next JS 版本 12+:静态站点生成
- django - 我应该向这个 API 发出请求/更改这个 API 的结构/改用数据库吗?
- c++ - 为许多客户端实现 UDP 服务器
- javascript - 如果 VictoryCandlestick OHLC 的值都相同,则显示一个点