Difference between revisions of "Count number of characters"

From LemonWiki共筆
Jump to: navigation, search
m
m
Line 14: Line 14:
 
* e.g. {{kbd | key=<nowiki>\r\n</nowiki>}} costs 2 characters
 
* e.g. {{kbd | key=<nowiki>\r\n</nowiki>}} costs 2 characters
  
Step3:
+
Step3: final formula
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 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)
  
 
[[Category:Software]] [[Category:Programming]] [[Category:Data Science]] [[Category:Text file processing]] [[Category:Data transformation]]
 
[[Category:Software]] [[Category:Programming]] [[Category:Data Science]] [[Category:Text file processing]] [[Category:Data transformation]]

Revision as of 18:54, 2 October 2019

Count number of characters in different approaches

BASH

Step1: Using Linux wc command

# print the character counts of txt files (contains the count of return symbol)
wc -m *.txt

# print the newline counts of txt files
wc -l *.txt

Step2: Check the Return symbol

  • e.g. \r\n costs 2 characters

Step3: final formula

Number of characters (not contains the return symbol) = result of wc -m *.txt - result of wc -m *.txt * 2 - 1 (the last blank line costs 1 character)