Tuesday, March 23, 2010

WC

Short for word count, wc displays a count of lines, words, and characters in a file.

wc [-c | -m | -C ] [-l] [-w] [ file ... ]
-cCount bytes.
-mCount characters.
-CSame as -m.
-lCount lines.
-wCount words delimited by white space characters or new line characters. Delimiting characters are Extended Unix Code (EUC) characters from any code set defined by iswspace()
fileName of file to word count.
Examples
wc myfile.txt - Displays information about the file myfile.txt. Below is an example of the output.
5    13    57   myfile.txt
5 = Lines
13 = Words
57 = Characters


$ wc foo bar
     40     149     947 foo
   2294   16638   97724 bar
   2334   16787   98671 total

  • wc -l print the line count
  • wc -c print the byte count
  • wc -m print the character count
  • wc -L print the length of longest line
  • wc -w print the word count
who | wc -l
 counts the number of users logged

ps -e | wc -l
counts the number of processes
ls -l | grep ^d | wc -l  # finds the number of subdirectories in the current directory.
wc -l /etc/passwd
 tells you the number of lines (accounts) in the /etc/passwd file.
wc -w readme.txt
 counts the number of words in the file named readme.txt

No comments:

Post a Comment