The command cat /etc/redhat-release
returns:
CentOS Linux release 5.6.1804 (Core)
How do I select only the 5?
i tried
cat /etc/redhat-release | awk '{print $4}'
and it returns this:
5.6.1804
but I only want the first number.
The command cat /etc/redhat-release
returns:
CentOS Linux release 5.6.1804 (Core)
How do I select only the 5?
i tried
cat /etc/redhat-release | awk '{print $4}'
and it returns this:
5.6.1804
but I only want the first number.
You can with a combination of
awk
andcut
Or with
grep
Which gets the digits between a space and a period.
Another variant of
grep
is:If you want to use
awk
only you would have to get the first of the digits, which you can easily solve usingsplit()
:This function will build an array separating the release value for each point. The first value of this array will be the version number you are looking for.
The first awk allows the fourth field of the line to be selected, then another awk is added to process the output of the first and takes the period ( . ) as the separator. In this way, the first field of the first output is selected and thus give a solution to the problem posed.