Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a single digit integer for RHEL version using SED or AWK

I can get the 5.8 or 6.4 number from looking at /etc/redhat-release, but I don't know how to get it converted from 5.8 to just 5. The command I'm using so far is:

cat /etc/redhat-release | awk {'print $7'}

Which produces the 5.8. How would I go about getting the single digit integer from that using bash?

like image 992
FilBot3 Avatar asked Aug 31 '25 05:08

FilBot3


1 Answers

Or use int() function:

cat /etc/redhat-release | awk '{print int($7)}'


$ cat /etc/redhat-release | awk {'print $7'}
5.8
$ cat /etc/redhat-release | awk '{print int($7)}'
5
like image 103
jaypal singh Avatar answered Sep 02 '25 20:09

jaypal singh