You could leave the command as is and use @AndreyDeineko's valid solution.
You could execute the grep command inside Ruby with String#scan:
abc   = 'AS35995'
whois = `whois -h whois.radb.net -- '-i origin #{abc}'`
# route:      8.25.194.0/23
# descr:      Twitter
# origin:     AS35995
# admin-c:    NETWO3685-ARIN
# tech-c:     NETWO3685-ARIN
# notify:     noc@twitter.com
# mnt-by:     MAINT-AS13414
# changed:    ck@twitter.com 20121028  #17:03:09Z
# source:     RADB
# route:      8.25.196.0/23
# descr:      Twitter
# origin:     AS35995
# ....
p routes = whois.scan(/[\d\.]{7,}\/\d+/)
#=> ["8.25.194.0/23", "8.25.196.0/23", "192.133.78.0/23", "8.25.194.0/24", "8.25.195.0/24", "8.25.196.0/24", "8.25.197.0/24", "185.45.4.0/24", "103.252.112.0/23", "185.45.4.0/23"]
This regex is simple but might match too much. From this link, it looks like a more accurate regex would be :
/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/\d+\b/
Route is now an array of strings, containing the route values from whois.
Finally, it seems you could also execute whois with this gem.