4

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?

FilBot3
  • 3,460
  • 6
  • 33
  • 55

2 Answers2

4

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
jaypal singh
  • 74,723
  • 23
  • 102
  • 147
3

Add a format specifier:

cat /etc/redhat-release | awk '{printf "%d", $7}'
devnull
  • 118,548
  • 33
  • 236
  • 227
  • At the end of your command, it seemed there was no newline, and thus my next prompt was right on top of the integer. Your command works just as I wanted. Thank you also. – FilBot3 Jun 27 '13 at 17:22