Reputation: 365
I would like to add a string to a sed output to form the complete path, I am not sure how I can concatenate the string to the result, how should I modify the following command? Any help would be appreciated.
$ go env | grep GOPATH | sed 's/.*="\(.*\)"/\1/'
/Users/Paul/go
# Would like to add /bin/hello to the above path with the end result
/Users/Paul/go/bin/hello
Upvotes: 1
Views: 478
Reputation: 133710
You could do this in a single awk
itself. My go env
output has GOPATH
like GOPATH="/root/go"
so I have taken care of "
part here, new values will be added before last "
by awk
.
go env | awk '/GOPATH/{gsub(/^GOPATH="|"$/,"");$0=$0 "/bin/hello";print;exit}'
2nd solution: Using sed
you could try following here. Stop printing of lines by -n
option of sed
and print only matching line which has GOPATH
in it, along with new values attached to it.
go env | sed -n '/GOPATH/ s|.*="\(.*\)"|\1/bin/hello|p'
Upvotes: 2