Shell Data Processing - (WC|Word Count) command (Line count)

Card Puncher Data Processing

About

The wc command is a filter that prints on one line sequentially the number of:

from:

  • files
  • or from an input stream when:
    • no FILE is specified
    • or the file argument - is specified

Example

With Standard Input from a pipeline

  • with the file hello.txt. You can create it with the below command in bash that uses echo gnu.
/bin/echo -e 'Hello\nWorld' > hello.txt
# -e takes the sequence character \n has an end of line
Hello
World

cat hello.txt | wc # read from the input stream created by cat
2       2      12

With Manual Standard Input (Copy / Paste )

wc -
  • Manually:
    • Type your text
    • or copy/paste:
      • in bash, right click to paste,
      • in dos, ctrl+v
  • Then send and end of file character
    • in bash: Ctrl+D
    • in dos: Ctrl+Z (^Z) on Windows

Example when copy/pasting

The wc command is a filter that prints on one line sequentially the number of:

newlines (lines),
words,
and characters

5      20     120 -

With a file as argument

When using a file name as argument

wc hello.txt # transform hello.txt as an input stream and read 
2  2 12 hello.txt

With a glob pattern that select files as argument

with a a glob pattern that select all files that begins with hello

wc hello*
2  2 12 hello.txt
 1  2 12 helloIn.txt
 1  2 12 helloOut.txt
 4  6 36 total

Syntax

wc [OPTION]... [FILE]...

where option can be

  • -c, –bytes: print the byte counts
  • -m, –chars: print the character counts
  • -l, –lines: print the newline counts
  • -L, –max-line-length
  • -w, –words: print the word counts





Discover More
CPU - Linux

CPU in a Linux context You can use the top or htop command line to get CPU monitoring metrics. where: x86_64 means: a X86 architecture with a 64 bit word size 1 block of information...
Bash Liste Des Attaques Ovh
Linux - File

Linux file management See Using Parameters Expansion Removal From a path string where the file does not exist dirname returns the first parent of an existing path file. ...
Card Puncher Data Processing
R - Read.Table

The Read.Table function reads a file in table format and creates a data frame from it, with cases corresponding to lines and variables to fields in the file. where: file can be a file, an Url or...
Card Puncher Data Processing
Shell Data Processing - Filter (Stream Operator)

This page is pipeline operator in a shell language. They are known as filter in a shell language. It is a computer program or shell command (subroutine) that: read from standard input (stream)...
Bash Liste Des Attaques Ovh
What are Redirections in Bash? Example and how-to

This article talks shell redirections in the Bash shell. Through redirection you can direct the input and output of a command to and from other files and programs, and chain commands together in a pipeline....



Share this page:
Follow us:
Task Runner