theshell.ch/site/pages/cmd/advanced/wc.html
bevilj a6515acdb9 order pages for navigation
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@254 a672b425-5310-4d7a-af5c-997e18724b81
2018-11-18 20:38:56 +00:00

71 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
layout: page
author: Alessandro Luini
category-page: advanced
category-title: Advanced commands
tags: word count lines
title: wc
previous-page: pages/cmd/advanced/vi.html
---
The program reads either standard input or a list of files and
generates one or more of the following statistics: newline count,
word count, and byte count. If a list of files is provided, both
individual file and total statistics follow.
<h3>How to use</h3>
Sample execution of wc:
<pre>
wc file1.txt file2.txt
</pre>
will output:
<pre>
40 149 947 file1.txt
2294 16638 97724 file2.txt
2334 16787 98671 total
</pre>
The first column is the count of newlines, meaning that the text file
<code>file1.txt</code> has 40 newlines while bar has 2294 newlines-
resulting in a total of 2334 newlines. The second column indicates the
number of words in each text file showing that there are 149 words in <code>file1.txt</code>
and 16638 words in <code>file2.txt</code> giving a total of 16787 words.<br>
The last column indicates the number of characters in each text file, meaning that the file
<code>file1.txt</code> has 947 characters while bar has 97724 characters 98671
characters all in all.<br>
<h3>Flags</h3>
<pre>
wc -l file1.txt
</pre>
Prints the line count (note that if the last line does not have <code>\n</code>,
it will not be counted).
<pre>
wc -c file1.txt
</pre>
Prints the byte count.
<pre>
wc -m file1.txt
</pre>
Prints the character count.
<pre>
wc -L file1.txt
</pre>
Prints the length of longest line (GNU extension)
<pre>
wc -w file1.txt
</pre>
Prints the word count.