Count number of characters: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
 
Line 98: Line 98:
== How to count characters with BASH ==
== How to count characters with BASH ==
Step1: Using [https://www.computerhope.com/unix/uwc.htm Linux wc command]
Step1: Using [https://www.computerhope.com/unix/uwc.htm Linux wc command]
<pre>
# Count the total number of characters in a file named "input.txt", while ignoring all whitespace characters (including spaces, tabs, newlines, etc.).
tr -d '\r\n[:space:]' < input.txt | wc -m
</pre>
<pre>
<pre>
# print the character counts of txt files (contains the count of return symbol)
# print the character counts of txt files (contains the count of return symbol)
Line 115: Line 121:


Number of characters (not contains the [[Return symbol | return symbol]]) = result of {{kbd | key=<nowiki>wc -m *.txt</nowiki>}} - result of {{kbd | key=<nowiki>wc -m *.txt</nowiki>}} * 2 - 1 (the last blank line costs 1 character) - number of the whitespaces
Number of characters (not contains the [[Return symbol | return symbol]]) = result of {{kbd | key=<nowiki>wc -m *.txt</nowiki>}} - result of {{kbd | key=<nowiki>wc -m *.txt</nowiki>}} * 2 - 1 (the last blank line costs 1 character) - number of the whitespaces


== How to count characters with Python ==
== How to count characters with Python ==

Navigation menu