-1

How can i count characters, words and lines from a file with wc command?

3
  • 4
    does wc --help not work? Mar 25, 2010 at 11:55
  • 1
    Try: man wc .
    – Yacoby
    Mar 25, 2010 at 11:56
  • 1
    look at the man wc page. or info wc page
    – user31894
    Mar 25, 2010 at 11:57

2 Answers 2

5

Lines: wc -l filename.txt

Characters: wc -m filename.txt

Words: wc -w filename.txt

http://www.computerhope.com/unix/uwc.htm

1

Wc command prints newline, word, and byte counts for each FILE, and a total line, if more than one FILE is specified.

Syntax

wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F

Option

-c:- print the byte counts
-m:- print the character counts
-l:- print the newline counts
-L:- print the length of the longest line
-W:- print the word counts
–help:- Print help
–version:- Display version information

You can use wc command as shown below to get the required information.

Use -m option to get the Character count

wc -m test_file.txt

-w option to print words count

wc -w test_file.txt

-l option to print newline count

wc -l test_file.txt

Note:- wc works on “/n” lines character. It counts the newline not the number of lines. The count will be one less is there is no newline character. Refer Why does wc -l tell me that this non-empty file has 0 lines?

I hope I answered your question.

You must log in to answer this question.