I have the following link from my local deployment:
https://localhost/internal-repo/test-tools/local-repo/docker-image-internal-1.2-dirty.tgz
I want to return only 1.2-dirty, I started with:
less version.txt | awk 'NR==1 {print $1}'
but it returns the whole link.
Do you have any idea how I can proceed?
>Solution :
You can something like this:
awk -F'[-/]' '{gsub(/\.[^.]+$/, "", $NF); print $(NF-1) "-" $NF}'
-F'[-/]' sets the field separator to either ‘-‘ or ‘/’. This means that each part of the URL between ‘-‘ and ‘/’ will be treated as a separate field.
gsub(/\.[^.]+$/, "", $NF) uses the gsub function in AWK, which stands for "global substitution". It searches for a pattern in the specified field ($NF, which refers to the last field), and replaces it with the given string (in this case, an empty string)
print $(NF-1) "-" $NF prints the second-to-last field ($(NF-1)) followed by a hyphen and then the last field ($NF). This concatenation gives you the desired version string