expr / awk / sed:从repo URL获取git目录名

时间:2012-03-20 12:11:52

标签: regex bash sed awk

使用 bash expr sed awk ,如何确定给定git repo的git基目录?

例如: git@git.gitweb.com:/myModule-repo.git =>的 Mymodule中回购

3 个答案:

答案 0 :(得分:5)

如果您坚持使用这些工具,

echo git@git.gitweb.com:/myModule-repo.git | sed 's%^.*/\([^/]*\)\.git$%\1%g'

(从最后一个/直到文学.git找到子串)应该做的伎俩,否则我会用

basename git@git.gitweb.com:/myModule-repo.git .git

执行相同的操作(同样,它更加透明,basename与POSIX一样sedawk)。

答案 1 :(得分:0)

echo "git@git.gitweb.com:/myModule-repo.git" | sed 's|git@git.gitweb.com:/||;s/.git//'

答案 2 :(得分:0)

echo git@git.gitweb.com:/myModule-repo.git | awk 'BEGIN {FS="/"} {print substr ($2, 1, 13)}'