1

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?

  • 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](askubuntu.com/editing-help – DK Bose Dec 3 '19 at 14:39
3

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.

  • @JusticeforMonica Thanks, I was about to edit the post. – Johnny Dec 3 '19 at 14:42
  • In the first part of the answer, the explanation of what each piece does is quite helpful. Can an explanation be added to the second part to describe what NR==1 does? – knot22 Dec 3 '19 at 14:48
  • @knot22 Edited. – Johnny Dec 3 '19 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.