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.
Start with
$ info wc
The info page gives a brief description of output format. If that doesn't give you enough to work with, grab the coreutils source and read wc's source code.