Wc
wc is a little program that counts the number of lines, words, and bytes (characters) of a plain text file.
Contents |
[edit] 1 Examples
[edit] 2 A single file
The order goes lines, words, characters/bytes, filename.
wc textfile
958 1290 77366 textfile
[edit] 3 Multiple files
wc textfile1 textfile2
772 6184 51267 textfile1
1039 11798 86461 textfile2
1811 17982 137728 total
[edit] 4 Lines, words, or characters only
[edit] 4.1 Lines
wc -l disprot_fasta_v3.5.txt
4731 disprot_fasta_v3.5.txt
[edit] 4.2 Words
wc -w disprot_fasta_v3.5.txt
5397 disprot_fasta_v3.5.txt
[edit] 4.3 Characters
Equivalent to -c if the current locale does not support multibyte characters.
wc -m disprot_fasta_v3.5.txt 243986 disprot_fasta_v3.5.txt
[edit] 4.4 Bytes
wc -c disprot_fasta_v3.5.txt 243986 disprot_fasta_v3.5.txt
[edit] 4.5 Getting a value into a variable =
Since the regular program, use a pipe or I/O redirection as further explained below:
lines=`wc -l < FILENAME`
[edit] 5 Using standard input
[edit] 5.1 Using pipes
cat textfile1 textfile2 | wc
76 76 1444
[edit] 5.2 Using I/O Redirection
wc < textfile
76 76 1444
[edit] 6 Counting the number of sequences in a fasta file
grep ">" FILE | wc -l grep ">" < INPUT | wc -l
The grep will find all of the name lines by searching for the name lines starting with ">" and the wc will count the lines and print out the number.