Search code examples
linuxbashawkgrepcut

extracting ideal string using awk


I have the sample distro version:

16.04.4 LTS (Xenial Xerus)

I want to extract 16.04 from that. So I did:

if [ -f /etc/os-release ]; then
    . /etc/os-release
    echo $VERSION | awk '{print $1}' | awk -F. '{print $1$2}'
fi

Output is:

1604

But I want to have:

16.04

Solution

  • Use Linux Standard Base tool lsb_release -r -s to get the distribution release number.

    More info: man lsb_release