Loading...
Uncategorized

Pipes, Filters, Head and Tail

Pipes:
A pipe is used to connect the output of one program or command to the input of another program or command without a temporary file. We use the symbol “|” for pipes

$ cat list.out |sort
$ cat list.out |wc -1

Filters:
Shell script are often called on to manipulate and reformat the output from commands that they execute. Sometimes this task is as simple as displaying only part of the output by filtering out certain lines. In most instances, the processing required is much more sophisticated. Now we see few basic text filtering commands with examples.

Head:
head
is a program on UNIX and Unix-like systems used to display the first few lines of a text file or piped data. By default it will show the first 10 lines of a file.
Syntax: head [ -number | -n number] filename

$ head list.out
$ head -n 20 list.out
$ head -20 list.out

Tail:
tail
is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data. By default it will show the last 10 lines of a file.
Syntax: tail [option] filename

$ tail -n 5 flavours.txt ## Prints the last five lines of the file
$ tail -f /var/log/massage ## To see the output of the appended lines to the file we use -f option.

Leave a Reply

Your email address will not be published. Required fields are marked *