I count errors in a log file by doing grep error logfile | wc -l
It outputs 10
I want to print Error count found in logfile is 10
I think need to pipe it thru echo but how can I append 10 to echo output?
I tried
var="$(grep -i error logfile | wc -l)" | echo "Error count found in logfile is $var"
you should not pipe the var into echo, but instead run them in sequence:
var="$(grep -i error * | wc -l)"
echo "Error count found in logfile is $var"
or you can define the variable just for the echo command, by doing with bash:
var="$(grep -i error * | wc -l)" ; echo "Error count found in logfile is $var"
As said in the comments below, of course you can embed your command call in your echo statement:
echo "Error count found in logfile is $(grep -i error * | wc -l)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With