Overview¶
stdin
, stdout
, And The Pipe¶
Good Ol’ Unix philosopy
A program does just one thing, and it does that well!Combining programs via the pipe
Connect one program’s standard output with another program’s standard input
⟶ multiple tools connected toether in a pipeline
Most text/line based
Configuration files
Logfile
Programm source
…
stdin
, stdout
: Examples¶
Counting lines from
stdin
$ wc -l line 1 line 2 line 3 ^D 3
^D
: end of file whenstdin
is terminal/consoleCounting lines from
/etc/passwd
$ wc -l < /etc/passwd 47
wc
reads/etc/passwd
fromstdin
, arranged by the shellFinally: redirecting
stdout
$ wc -l > num-lines line 1 line 2 line 3 ^D $ cat num-lines 3
Pipe: Examples¶
How many groups am I member of?
$ cat /etc/group | grep jfasch | wc -l 2
Equivalent (though more efficient):
$ grep jfasch < /etc/group | wc -l 2
Equivalent:
$ grep jfasch /etc/group | wc -l 2
Number of
#include
directives in Linux kernel source$ find ~/work/linux -name '*.[hc]' -exec cat {} \; | grep '^#include' | wc -l 325324
Equivalent (though more efficient):
$ find ~/work/linux -name '*.[hc]' | xargs cat | grep '^#include' | wc -l 325324
Basics Text Tools¶
Command |
Description |
---|---|
|
Write file content to |
|
Write first couple of line to |
|
Write last couple of line to |
|
Cut out fields from lines (according to configurable field separator) |
|
Page file content to |
|
Sort lines and write to |
|
Eliminate consecutive equal lines (ideally, in a pipe after
|
|
Filter lines by regular expression |