$ cut :: This command is used to retreive the required fields or characters from a file.
| 100 |
Rakesh |
UNIX |
HYD |
| 101 |
Ramani |
C++ |
CHE |
| 102 |
Prabhu |
C |
BAN |
| 103 |
Jyosh |
DWH |
CHE |
syntax - $cut -f 1-3 filename
eg. $cut -f 0-2 employee (all the fields in the above file)
| 100 |
Rakesh |
UNIX |
| 101 |
Ramani |
C++ |
| 102 |
Prabhu |
C |
| 103 |
Jyosh |
DWH |
eg. $cut -c 1-8 employee (first 8 characters)
| 100 |
Rake |
| 101 |
Rama |
| 102 |
Prab |
| 103 |
Jyos |
Delimeters
| Default ( Tab ) |
| : |
, |
; |
* |
_ |
$cut options
$cut -f 0-2 employee
$cut -c 1-8 employee
$cut -d ',' 1-8 employee
$ sort :: This command is used to sort the file records in ascending or descending
$sort Options
$sort -r filename (reverse)
$sort -u filename (unique records)
$sort -n filename(show the number along sorting)
How to sort data in field wise ?
syntax- $sort -f +pos1 -pos2 filename
eg. $sort -f +1 -2 employee
$ uniq :: This command is used to filter the duplicate lines from a file
Note :: Always the file must be in sorting order.
syntax - $uniq filename
eg. $uniq employee
$uniq Options
eg. $uniq -u employee (displays non duplicated lines)
eg. $uniq -d employee ( displays duplicated lines)
Question ::
Q) How to remove duplicate lines in a file?
A) $uniq employee>temp
$mv temp employee
|