How do I get a part of the output of a command in Linux Bash?

后端 未结 4 1990
我寻月下人不归
我寻月下人不归 2021-02-06 16:08

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         


        
4条回答
  •  借酒劲吻你
    2021-02-06 16:41

    If you want all the lines that contain "php", do this:

     $ php -v | grep -i "php"
    

    Then if you want the first three words within those, you can add another pipe as @Avinash suggested:

    $ php -v | grep -i "php" | awk 'NR==1{print $1,$2,$3}'
    

提交回复
热议问题