Linux Shell Scripting Tutorial (LSST) v1.05r3
Prev
Chapter 5: Essential Utilities for Power User
Next

Selecting portion of a file using cut utility

Suppose from sname file you wish to print name of student on-screen, then from shell (Your command prompt i.e. $) issue command as follows:
$cut -f2 sname
Vivek
Renuka
Prakash
Ashish
Rani


cut utility cuts out selected data from sname file. To select Sr.no. field from sname give command as follows:
$cut -f1 sname
11
12
13
14
15

CommandExplanation
cut   Name of cut utility
-f1 Using (-f) option, you are specifying the extraction field number. (In this example its 1 i.e. first field)
snameFile which is used by cut utility and which is use as input for cut utility.

You can redirect output of cut utility as follows
$cut -f2 sname > /tmp/sn.tmp.$$
$cut -f2 smark > /tmp/sm.tmp.$$
$cat /tmp/sn.tmp.$$

Vivek
Renuka
Prakash
Ashish
Rani

$cat /tmp/sm.tmp.$$
67
55
96
36
67

General Syntax of cut utility:
Syntax:
cut -f{field number} {file-name}

Use of Cut utility:
Selecting portion of a file.


Prev
Home
Next
Preparing for Quick Tour of essential utilities
Up
Putting lines together using paste utility