Search code examples
unixsemanticswc

Confuse with the command wc -l and wc in unix


In the file.txt, it contains

Good is good
Bad
Gp
TR

What I run the command

wc file.txt 

it produces 4 6 23..........I still don't quite understand how do 4 6 23 arrive?

Also when I run the command

wc -l file.txt

it produces 4 which means the number of rows in the file..Am I right?


Solution

  • it produces 4 6 23..........I still don't quite understand how do 4 6 23 arrive?

    It means:

    • 4 denotes that there are 4 lines in complete Input_file.
    • 6 denotes that there are 6 words in complete Input_file.
    • 23 tells us that there are 23 characters present in whole file.

    So this output only comes when we do not pass any option to wc, in case you need to get these details very specifically then use something like: wc -l to get lines and wc -c to get number of characters in Input_file.

    From man wc:

    DESCRIPTION Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input. A word is a non-zero-length sequence of characters delimited by white space. The options below may be used to select which counts are printed, always in the following order: newline, word, character, byte, maximum line length.