I need to write a perl that mimic linux command wc exactly(including and especially output format), while having realized the functionality, the output of wc is really a headache, it seems that it is changing all the time, the following are a few examples(I will use □ to represent space character)
1. wc test_input_1 ⇒ □□705673□□4234032□26754553□test_input_1
2. wc test_input_2 ⇒ □14□□79□581□test_input_2
3. wc test_input_2 -w ⇒ 79□test_input_2
4. wc test_input_2 -wc ⇒ □79□581□test_input_2
5. cat test_input_2 | wc ⇒ □□□□□14□□□□□□79□□□□□581
6. cat test_input_2 | wc -w ⇒ 79
7. cat test_input_2 | wc -wc ⇒ □□□□□79□□□□□581
anyone knows how wc formats its output? Any help is appreciated, thanks a lot.
If you came here (from a search engine) to find which numbers wc prints out by default as you don't know how to interpret it's output and are annoyed all other answers just lead you to man/info pages and other resources you actually need to read, here is your quick Stackoverflow moment reliving you of your grief:
info wc, as suggested by @converter42, explains it somewhere hidden:
By default, ‘wc’ prints three counts: the newline, words, and byte counts.
FYI also man wc menttions it in a subtle way right at the beginning of the description:
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified.
For example:
$ wc
abc def
xyz
[Ctrl+D] 2 3 12
= 2 (new)lines, 3 words and 12 bytes
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