Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx Version + AWK Not Working

Tags:

awk

Today I've noticed that I can't use "awk" on "nginx -v".

I've tried running this command: nginx -v | awk -F/ '{print $2}'

This should of been output like this: nginx/1.4.3

But instead it gives me nginx version: nginx/1.4.3

Any idea why it would behave this way !?

Also you can't output it to file by running: nginx -v > file.txt

like image 618
Tux Avatar asked Aug 15 '26 11:08

Tux


1 Answers

nginx must be writing that message to standard error, not standard output. If you want to pipe it, you have to redirect stderr to stdout:

nginx -v 2>&1 | awk -F/ '{print $2}'
like image 82
Barmar Avatar answered Aug 18 '26 03:08

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!