Simple Filters
Simple Filters
Simple Filters
$ head emp.lst
• U can use –n option to specify the line count and
display the first three lines of the file
$ head –n 3 emp.lst
2233|a.k.shukla|g.m.|sales|12/12/52| 6000
9876|jaiSharma|director|production|03/12/50|7000
9876|jaiSharma|director|production|03/12/50|7000
5678|sumitchakrobarty|d.g.m|marketing|04/19/43|600
2365|barunsengupta|director|personnel|05/11/47|780
5423|n.k.gupta|chairman|admin|08/30/56|5400
Cutting columns(-c)
a.k.shukla gm
jai sharma director
sumit chakrobrty d.g.m
barun sengupta director
n.k.gupta chairman
2233|a.k.shukla|g.m|sales |12/12/52|6000
2365|barunsengupta|director|personnel|05/11/47|7800
9876|jaiSharma|director|production|03/12/50|7000
5423|n.k.gupta |chairman|admin |08/30/56|5400
5678|sumit chakrobarty|d.g.m |marketing |04/19/43|6000
• The sort order can be reversed with –r(reverse)
option
• Sort –t “|” –r –k 2 shortlist
5678|sumitchakrobarty|d.g.m|marketing|04/19/43|6000
5423|n.k.gupta |chairman|admin |08/30/56|5400
9876|jai Sharma |director |production |03/12/50|7000
2365|barun sengupta |director |personnel|05/11/47|7800
2233|a.k.shukla |g.m |sales |12/12/52|6000
Sorting on columns:
• $ sort numfile
10
2
27
4
• So if you want to sort according to numbers
• $ sort –n numfile
2
4
10
27
Predict if want to reverse the order
Removing repeated lines(-u)
• The –u(unique)option lets you remove repeated lines
from a file
• If you “cut” out the designation field from shortlist
you can pipe it to sort to find out the unique
designations that occur in the file
• $ cut –d “|” –f3 shortlist | sort -u
chairman
d.g.m
director
executive
g.m
manager
Other sort options
• Even though sorts output can be redirected to
a file,we can use its –o option to specify the
output filename
d.g.m
director
g.m.
Counting frequency of occurrence(-c):
• The –c (count) option displays the frequency
of occurrence of all the lines
5678~sumitchakrobarty~d.g.m~marketing~04-19-43~6000
2233|A.K.SHUKLA|G.M|SALES|12/12/52|6000
9876|JAISHARMA|DIRECTOR|PRODUCTION|12/03/50|7000
5678|SUMIT CHK |D.G.M|MARKETING|19/04/43|6000
$pr –t -5 a.out
0 4 8 12 16
1 5 9 13 17
2 6 10 14 18
3 7 11 15 19
• There are other various options such as:
• -d doublespaces input
• -n number of lines
• -o n:offsets the lines by n spaces,increases left
margin of page
• Combine these various options to produce just
the format you need:
• $ pr –t –n –d –o 10 dept.lst
1 01|accounts|6213
2 02|admin|5243
3 03|marketing|6521
4 04|personnel|2365
5 05|production|9876
6 06|sales|1006
• There is one option that uses a number prefixed
by a + to print from a specific page number
• -l option sets the page length