Bash: how to take a number from string? (regular expression maybe)
bash, grep, regex
Solution
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]}"
Problem
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?