How do I get a part of the output of a command in Bash?
For example, the command php -v
outputs:
PHP 5.3.28 (cli) (built: Jun 23 2014 16:25:09
You could try the below AWK command,
$ php -v | awk 'NR==1{print $1,$2,$3}'
PHP 5.3.28 (cli)
It prints the first three columns from the first line of input.
NR==1
(condition)ie, execute the statements within {}
only if the value of NR variable is 1.{print $1,$2,$3}
Print col1,col2,col3. ,
in the print statement means OFS (output field separator).