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

后端 未结 4 1984
我寻月下人不归
我寻月下人不归 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:33

    In pure Bash you can do

    echo 'PHP 5.3.28 (cli) (built: Jun 23 2014 16:25:09)' | cut -d '(' -f 1,2
    

    Output:

    PHP 5.3.28 (cli)
    

    Or using space as the delimiter:

    echo 'PHP 5.3.28 (cli) (built: Jun 23 2014 16:25:09)' | cut -d ' ' -f 1,2,3
    

提交回复
热议问题