Home > Enterprise >  How to use grep and awk together to get specific part of a url/string
How to use grep and awk together to get specific part of a url/string

Time:02-23

So I have a svn repo URL like this--

svn info
Path: .
URL: svn://xyz-repo/svn/ccsmp/branches/features/cre40_jenkins
Repository Root: svn://xyz-repo/svn/ccsmp
Repository UUID: 5de8f2f4-0d3b-0410-8f2c-d418a2640d16
Revision: 23430

I want to grab only this part--

branches/features/cre40_jenkins

So far I have tried something like this

def BRANCH_NAME = sh(script: " svn info | grep -Po 'Relative URL: \\^/\\K.*' ", returnStdout: true , trim: true)

But this didn't worked as I am using a very old Jenkins version with old plugins and svn.

Is there any other way to do this. Please help any suggestions would be highly appreciated.

CodePudding user response:

def BRANCH_NAME = sh(script:""" cat svn info | grep URL | cut -d "-" -f2 | cut -d "/" -f 4-6 """, returnStdout: true , trim: true)

output : branches/features/cre40_jenkins

  • Related