-1

Have inputs like

url1='http://10.25.225.123:32782/actuator/health' url2='http://10.25.225.321:12345/myappmanagement/health' and so on.

How to get only http://10.25.225.123:32782/ and http://10.25.225.321:12345 for url1 and url2 respectively using the same command?

Prem
  • 316
  • 1
  • 5
  • 23

1 Answers1

1
url='http://10.25.225.123:32782/actuator/health'
awk -F'/' 'BEGIN{OFS=FS="/"} {print $1,$2,$3}' <<< "$url"
http://10.25.225.123:32782

or simply:

cut -d/ -f-3 <<< "$url"
http://10.25.225.123:32782
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • `/actuator` can also change to something else. – Prem Dec 16 '22 at 11:08
  • Hi @Gilles Quenot, Thanks for the reply. I forgot that there could be a different value than `actuator` un URL. I have updated the question. Please help on the same. – Prem Dec 16 '22 at 11:25