Wc: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:


The number of lines in each input file is written to the standard output.
The number of lines in each input file is written to the standard output.
To get the number of lines from a single file as a number:
<syntaxhighlight lang='bash'>
cat file.txt | wc -l | awk '{print $1}'
</syntaxhighlight>


==-c==
==-c==


The number of bytes in each input file is written to the standard output.  This will cancel out any prior usage of the [[#-m|-m]] option.
The number of bytes in each input file is written to the standard output.  This will cancel out any prior usage of the [[#-m|-m]] option.
 
<syntaxhighlight lang='bash'>
wc -c somefile.txt | awk '{print $1}'
wc -c somefile.txt | awk '{print $1}'
</syntaxhighlight>
To test non-zero length file, use [[Bash test#-s|bash test -s]].


==-m==
==-m==

Latest revision as of 23:14, 12 April 2022

Internal

Options

-l

The number of lines in each input file is written to the standard output.

To get the number of lines from a single file as a number:

cat file.txt | wc -l | awk '{print $1}'

-c

The number of bytes in each input file is written to the standard output. This will cancel out any prior usage of the -m option.

wc -c somefile.txt | awk '{print $1}'

To test non-zero length file, use bash test -s.

-m

The number of characters in each input file is written to the standard output. If the current locale does not support multibyte characters, this is equivalent to the -c option. This will cancel out any prior usage of the -c option.

-w

The number of words in each input file is written to the standard output.