jhintu jhintu - 2 months ago 9
Bash Question

Extract string using : as delimiter in shell

I have a string

"inet6 addr: 2620:cb:0:b007::23c3/112 Scope:Global",


and I want to extract only

"2620:cb:0:b007::23c3"


from the above string.

How can I extract the substring using cut/sed/awk command.

Answer

I am too new in shell but with cut command, it would be like:

   cut -f2-7 -d":" | cut -f1 -d "/"
Comments