bash - 匹配单词组并打印然后仅使用 sed 或 awk
问题描述
使用 sed 或 awk ,我如何仅匹配和organization
打印repo
git@github.org.com/organization/repo.git
?
我的意图是将这两个值分配给变量,以便在我正在构建的东西中使用,以便为组织和存储库创建本地文件夹。
期望的结果将是organization/repo
唯一的。
目前为了继续我正在使用cut -f2 -d':' | cut -f1 -d'
,但我对 push this 感到羞耻。
解决方案
Since you need to create 2 shell variables it may be better to prefer a BASH solution.
You can use read
with IFS='./':
:
IFS='./:' read -ra arr <<< 'git@github.org.com/organization/repo.git'
echo "${arr[3]}/${arr[4]}"
organization/repo
IFS='./:'
splits input string on DOT and/
and :colonread -a
populates an array from input text
推荐阅读
- android - 如何确保我的 UI 按钮使用统一的屏幕尺寸和方向缩放?
- r - dplyr 四舍五入和平均值
- php - 事件在 laravel 中看不到监听器
- python - setuptools_scm.version.SetuptoolsOutdatedWarning:您的 setuptools 太旧 (<12)
- sql - SQL - 计算价格的变量公式
- puppeteer - 查找/返回文本
- apache-kafka - Kafka如何处理各种故障情况
- python - 试图创建一个忽略属于组的字符以及跟随一组字符的单词的正则表达式
- python - 输出的周数字符串是否正确?
- mysql - SQLSTATE [42000]:语法错误或访问冲突:1044 拒绝用户 'ion'@'localhost' 访问数据库 'a901ce392dad4b90b1c6e175b07196a9'