gerrit_url=http://a/1234/11/+/1666,我想用linux筛选出+/后面的数字该怎么办
时间: 2023-08-10 20:04:30 浏览: 198
要从 `gerrit_url` 中提取出 `+/` 后面的数字,可以使用 Linux 命令行工具中的字符串操作和正则表达式。
下面是一个使用 `grep` 命令和正则表达式的示例:
```shell
echo "gerrit_url=http://a/1234/11/+/1666" | grep -oP '(?<=\+/)\d+'
```
解释:
- `echo "gerrit_url=http://a/1234/11/+/1666"` 用于将字符串输出到标准输出。
- `grep -oP '(?<=\+/)\d+'` 是使用 `grep` 命令,其中 `-o` 选项表示只输出匹配的部分,`-P` 选项表示使用 Perl 正则表达式。
- `(?<=\+/)` 是一个正向查找,表示匹配 `+/`,但不包括在结果中。
- `\d+` 表示匹配一个或多个数字。
运行上述命令后,将输出 `1666`,即 `+/` 后面的数字。
请注意,上述命令仅适用于在 Linux 命令行环境下执行。如果你将其放入脚本中,请确保适当地将变量 `gerrit_url` 替换为实际的变量名。
相关问题
Project URl partner_modules http://10.24.71.91/gerrit/c/sharp/vendor/partner_modules/+/142367 WIFI http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Wifi/+/142279 Uwb http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Uwb/+/142278 StatsD http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/StatsD/+/142277 SdkExtensions http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/SdkExtensions/+/142276 Permission http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Permission/+/142274 OnDevicePersonalization http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/OnDevicePersonalization/+/142273 MediaProvider http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/MediaProvider/+/142272 Media http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Media/+/142271 IPsec http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/IPsec/+/142270 conscrypt http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/conscrypt/+/142269 Connectivity http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Connectivity/+/142268 art http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/art/+/142267 AppSearch http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/AppSearch/+/142264 AdServices http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/AdServices/+/142263 Scheduling http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Scheduling/+/142275给我生成Markdown表格
| Project | URL |
| --- | --- |
| partner_modules | http://10.24.71.91/gerrit/c/sharp/vendor/partner_modules/+/142367 |
| WIFI | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Wifi/+/142279 |
| Uwb | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Uwb/+/142278 |
| StatsD | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/StatsD/+/142277 |
| SdkExtensions | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/SdkExtensions/+/142276 |
| Permission | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Permission/+/142274 |
| OnDevicePersonalization | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/OnDevicePersonalization/+/142273 |
| MediaProvider | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/MediaProvider/+/142272 |
| Media | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Media/+/142271 |
| IPsec | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/IPsec/+/142270 |
| conscrypt | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/conscrypt/+/142269 |
| Connectivity | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Connectivity/+/142268 |
| art | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/art/+/142267 |
| AppSearch | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/AppSearch/+/142264 |
| AdServices | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/AdServices/+/142263 |
| Scheduling | http://10.24.71.91/gerrit/c/PCQ/platform/prebuilts/module_sdk/Scheduling/+/142275 |
<remote fetch="ssh://username_placeholder@172.16.16.121:29418/partner2/" name="origin" review="http://gerrit.longcheer.com"/>
这是一个 Git 中的远程仓库配置,其中使用 SSH 协议连接到 IP 地址为 172.16.16.121 的主机上的名为 partner2 的项目仓库,端口号为 29418。该远程仓库的名称为 origin,代码审核使用的工具为 Gerrit,审核地址为 http://gerrit.longcheer.com。
阅读全文