Commands: $ logname  to check present working user. User2 $ clear



Download 122.5 Kb.
Page17/17
Date25.10.2023
Size122.5 Kb.
#62396
1   ...   9   10   11   12   13   14   15   16   17
Unix Commands
Advanced Filters

Sort, cut, paste, uniq are the advanced filters

  • Sort

Sort command is used to sort the data files based on particular fields. Default sort is based on first field and will be in ascending order.
Syn: sort [file name]
Sort based on particular fields:
$ sort –t “:” –k 1, 2, 3… [Data file name]
Here “t” indicates field terminator. “k” indicates key (field number)
Sort based on 2nd field
$ sort –t “:” –k 2 [Data file name]
Sort in Descending order (reverse order) based on 2nd field
$ sort –rt “:” –k 2 [Data file name]
Ex:
To retrieve the record of Employee getting max Sal. Here empno is 1st field and sal is 3rd field
$ sort –rt “:” –k 3 emp.dat | head -1
Sort based on multiple fields (1st & 3rd field)
$ sort –t “:” –k 3, 3 –k 1 emp.dat
start at stop at
In Default when any two values are equal in the sorting fields then it goes for next field for comparison. So to stop the comparison at that field above type of syntax is used.

  • Cut

Cut command is used to get the particular fields of data file.
Syn: $ cut –d “:” –f 1, 2, 3... [Data file name]
Here “d” indicates delimiter (or) separator, f indicates field number.
Ex:
To get ename which is 2nd field and age of employee which is 6th field
$ cut –d “:” –f 2,6 emp.dat
aaa:25
bbb:32
To get Max sal
Download 122.5 Kb.

Share with your friends:
1   ...   9   10   11   12   13   14   15   16   17




The database is protected by copyright ©ininet.org 2024
send message

    Main page