linux command wc output format

user685275 picture user685275 · Apr 25, 2011 · Viewed 13.3k times · Source

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 -w79□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 -w79
7. cat test_input_2 | wc -wc□□□□□79□□□□□581

anyone knows how wc formats its output? Any help is appreciated, thanks a lot.

Answer

converter42 picture converter42 · Apr 25, 2011

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.