Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get only version number of a program? pipe into grep

Tags:

linux

grep

bash

rsync --version

gives lots of info but I just want to grab the first line

rsync  version 3.1.1

How to do this? I tried to pipe into grep but I can't

like image 200
kuruvi Avatar asked Sep 08 '25 14:09

kuruvi


1 Answers

There are lots of ways to slice this pie. If you want the whole first line, you can use any of these:

rsync --version | head -n 1
rsync --version | awk NR==1
rsync --version | sed -n 1p
rsync --version | grep '^rsync *version'

If you want just the version number without the rest of the line, that's not much harder, but it depends which part of the line you want. On my Mac, the version line reads rsync version 2.6.9 protocol version 29, and a naïve grab would likely yield the 29 - presumably not what you want. Either of the following will output just the 2.6.9 by itself:

rsync --version | awk 'NR==1 {print $3}'
rsync --version | sed -n '1s/^rsync *version \([0-9.]*\).*$/\1/p'
like image 100
Mark Reed Avatar answered Sep 10 '25 06:09

Mark Reed