2

When curl --version is executed on the command line of a VM running Ubuntu 18.04 this is displayed in the terminal:

curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

How do I change the command so that only 7.58.0 is displayed?

Kulfy
  • 17,696
knot22
  • 149
  • 2
  • 8
  • 1
    Posting terminal information as images makes it difficult for responders to use part of the output in their answers or in requests for clarification. Instead, copy and paste the relevant output here using this site's [markdown formatting](https://askubuntu.com/editing-help – DK Bose Dec 03 '19 at 14:39

1 Answers1

4

With a little modification.

:~$ curl --version | head -n 1 | awk '{ print $2 }'
7.58.0

head -n 1 tells shell to print the first line of output.

awk '{ print $2 }' will print the second column.


You can also tell awk to print the second column of the first line, using NR built-in variable.
:~$ curl --version | awk 'NR==1{print $2}'
7.58.0

NR==1 tells awk to print the first line of the output.

{ print $2 } will print the second column.

Liso
  • 15,377
  • 3
  • 51
  • 80