Get the first line of shell command output

When I try to read the vim version number, I get many extra lines that I need to ignore, I tried to read the manual headand tried the following command:

vim --version | head -n 1

I want to know if this is the right approach?

+4
source share
1 answer

Yes, this is one way to get the first line of output from a command.

If the command outputs something to the standard error that you would like to capture in the same way, you need to redirect the standard error of the command to the standard output stream:

utility 2>&1 | head -n 1

, sed q ( ) sed -n 1p ( ).

+9

Source: https://habr.com/ru/post/1684973/


All Articles