How can I count how many characters appear within a file, minus those from a specific list. Here is an example file:
你好吗?
我很好,你呢?
我也很好。
I want to exclude any occurrences of ?
, ,
, and 。
from the count. The output would look like this:
3
5
4
A pure bash solution:
while IFS= read -r l; do
l=${l//[?,。]/}
echo "${#l}"
done < file
Try
sed 's/[,。?]//g' file | perl -C -nle 'print length'
The sed
part removes unwanted characters, and the perl
part counts the remaining characters.
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