I want to get a count of symbols in a file.
wc -c f1.txt | grep [0-9]
But this code return a line where grep found numbers. I want to retrun only 38. How?
You can use awk:
wc -c f1.txt | awk '{print $1}'
OR using grep -o
:
wc -c f1.txt | grep -o "[0-9]\+"
OR using bash regex capabilities:
re="^ *([0-9]+)" && [[ "$(wc -c f1.txt)" =~ $re ]] && echo "${BASH_REMATCH[1]}"
pass data to wc
from stdin instead of a file: nchars=$(wc -c < f1.txt)
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