Search code examples
linuxbashcut

How extract a substring from string using bash commands


i want to extract the substring:

"1.0.119"

From:

"/abc/efg/v/y-1.0.119.u"

How it can be done?

(i get the whole string from a pipe)

Thanks


Solution

  • > echo "/abc/efg/v/y-1.0.119.u" | cut -d'-' -f2 | cut -d'.' -f1-3
    1.0.119
    
    • cut -d'-' -f2 returns what is after the first -.
    • cut -d'.' -f1-3 returns what is before the third ..