Issue
I've the following variables in bash script.
xyz-0.3.2-3
abc-xyz-tools-0.1-1
def-yz-7.3.0-1.0.0
Result should be for :
pkg: xyz and version of xyz : 0.3.2-3
pkg: abc-xyz-tools version of abc-xzy-tools: 0.1-1
pkg: def-yz version of def-yz: 7.3.0-1.0.0
Since the pkg names are of different word length and versions are of different lengths, it's slightly tricky.
Your help will be appreciated. (bash,sed,awk would be preferred lang)
Solution
EDIT: With package name code.
awk --re-interval '
match($0,/([a-zA-Z]+\-+){1,}/){
val=substr($0,RSTART,RLENGTH-1);
print "pkg: " val " and version of " val " : " substr($0,RSTART+RLENGTH)
}' Input_file
Could you please try following awk
and let me know if this helps you.(remove --re-interval
in case you have newer version of awk
with you).
awk --re-interval 'match($0,/([a-zA-Z]+\-+){1,}/){print substr($0,RSTART+RLENGTH)}' Input_file
Answered By - RavinderSingh13