-1

I'm creating a script to add multiple features to monitor many servers, and I want to add a custom output using echo command to show the total of records as result of the command that I have executed.

The purpose is to show the total number of services that are disabled, enabled, etc.

I used the command in the image, but I don't know what I'm doing wrong.

I need to get the result of 142.

Error:

enter image description here

  • 1
    So you want the number of lines in a file. Why not use wc -l? – Munir Apr 14 '16 at 19:42
  • Thanks. It work as well too. svcs | grep online | wc -l – vicdeveloper Apr 14 '16 at 20:24
  • svcs | grep -c online, too – Jeff Schaller Apr 14 '16 at 20:51
1

For speed and simplicity, I would pipe the command output into wc -l as Munir suggests. If you really want to use awk, just print the number of records in the END block:

awk 'END { print NR }'
  • Thanks. It works as well. I actually use: svcs | grep disable | awk 'END {print NR}' – vicdeveloper Apr 14 '16 at 20:25

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.