PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 17, 2022

[FIXED] How to grep following words from string

 August 17, 2022     awk, grep, linux, output, sed     No comments   

Issue

How can I grep the nodeport which is the "31000" under the PORT(S) , it can and will change, from the following kubernetes command output:

NAME       TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
vault-ui   NodePort   10.96.62.155   <none>        8200:31000/TCP   23m

and how can I grep the ip address(in this case 192.168.99.213) but not the port(8443) or the https:// in following output, this output also changes depending on the ip:

Kubernetes master is running at https://192.168.99.213:8443
KubeDNS is running at https://192.168.99.213:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Solution

kubecmd | awk -F[:] 'NR>1 { split($2,arr,"/");print arr[1]}'

For the first scenario, you can use awk as above. Use : as a field separator and then further split the second delimited piece on / into array arr printing the first element this array the

kubecmd | sed -En 's/(^.*Kubernetes master.*https:\/\/)(.*)(:.*$)/\2/p'

For the second scenario, use sed as above. Split the text into three sections and print the second section



Answered By - Raman Sailopal
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing