-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern
More file actions
339 lines (237 loc) · 8.96 KB
/
pattern
File metadata and controls
339 lines (237 loc) · 8.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
SP_123423,Montek,75
SP_714441,Forocot,105
TB_006745_10.Concor,250
TB_102030_25,lvabid,325
TB_100011_15.Zetamit,150
LoginID#Passwd#DateOfBirth#Location#Mobile#Email
Rajaravi#ETA@123#18-09-1993#Delhi#8888888888#raja.ravi@infosys.com
Rajesh#Infy123#16-08-1990#Chennai#9999999999#Rajesh@infosys.com
Raktim#123Infy#10-08-1992#Bangalore#8989898998#Raktim_talukdar@infosys.com;
Aravind#Dell123#12-08-1993#Hyderabad#7878787890#Aravind.raghavan@infosys.com
Sankavi#InfyDell#14-09-1992#Mumbai#7777777777#vidya@infosys.com
------------------------------------------------------------------------------------
a.Display all the login ids along with the terminal numbers of users who have logged into the server
b.Given a login id, count the number of times that particular user has logged in
c.Display the count of directories in your present working directory
d.Display all the lines in a file which ends with a semicolon
$ grep ';$' pattern1
e.Count the number of lines in a file which do not end with a semicolon.
$ grep -v ';$' pattern1| wc -l
************************************************************************************************************
employeee:
EmpNo#Email#Name#JobLevel#Experience
641357#Amrit_Mohanty#Amrit Mohanty#3#2
678522#Puneet_Mishra#Puneet Mishra#3#1
670242#Vikas_Bharti#Vikas Bharti#3#6
661822#Aravind_Raghavan#Aravind Raghavan#3#10
706209#Sankavi.Boopathy#Sankavi Boopathy#3#4
706452#Raja.Ravi#Raja Ravi#3#9
661777#Aravind_Sharma#Aravind Sharma#2#10
1.
Write a command to display the employee with the highest experience in years (last column)
$ grep ".*#` cut -d "#" -f5 employee|sort -n|uniq|tail -1`" employee
----------------
661822#Aravind_Raghavan#Aravind Raghavan#3#10
661777#Aravind_Sharma#Aravind Sharma#2#10
2.
Write a command to display all the employees whose first name have more than 6 characters
[tr1159773@MYSUL01K sep18]$ cut -d "#" -f3 employee| egrep -i '^[A-Z]{6,}'
Puneet Mishra
Aravind Raghavan
Sankavi Boopathy
Aravind Sharma
$ grep ".*# `cut -d "#" -f3 employee| egrep -i '^[A-Z]{6,}'`" employee
661822#Aravind_Raghavan#Aravind Raghavan#3#10
706209#Sankavi.Boopathy#Sankavi Boopathy#3#4
661777#Aravind_Sharma#Aravind Sharma#2#10
[tr1159773@MYSUL01K sep18]$ egrep '#[A-Za-z]{7,} ' employee
3.
EmpNo#Email#Name#JobLevel#Experience
641357#Amrit_Mohanty#Amrit Mohanty#3#610
670242#Vikas_Bharti#Vikas Bharti#3#2
661822#Aravind_Raghavan#Aravind Raghavan#3#10
706209#Sankavi.Boopathy#Sankavi Boopathy#3#4
706452#Raja.Ravi#Raja Ravi#3#9
678522#Puneet_Mishra#Puneet Mishra#3#1
661777#Aravind_Sharma#Aravind Sharma#2#10
Write a command to display two employees with least years of experience
sort -nk5 -t'#' Employee.txt | tail -3 | head -2
EmpNo#Email#Name#JobLevel#Experience
641357#Amrit_Mohanty#Amrit Mohanty#3#2
678522#Puneet_Mishra#Puneet Mishra#3#1
670242#Vikas_Bharti#Vikas Bharti#3#5.5
661822#Aravind_Raghavan#Aravind Raghavan#3#6.5
706209#Sankavi.Boopathy#Sankavi Boopathy#3#1.5
706452#Raja.Ravi#Raja Ravi#3#0.5
4.
Write a command to display all repetitive years of experience values
uniq -d
[tr1159773@MYSUL01K sep18]$ sort -nk5 -t'#' employee1 | head -3 | tail -2
678522#Puneet_Mishra#Puneet Mishra#3#1
670242#Vikas_Bharti#Vikas Bharti#3#2
III) marks
EmpNo#FA1#FA2#FA3
641357#67#75#78
678522#89#98#92
670242#89#97#99
661822#78#94#91
706209#67#34#65
706452#80#70#68
1.
Write a command to display two least marks in FA2
[tr1159773@MYSUL01K sep18]$ sort -t "#" -nk3 marks| head -3|tail -2
641357#67#75#78
661822#78#94#91
2.
Write a command to get all marks in 80s range scored in FA2
[tr1159773@MYSUL01K sep18]$ grep "#.*#8.#" mru
[tr1159773@MYSUL01K sep18]$
Write a command to get all marks in 90s range scored in FA2
[tr1159773@MYSUL01K sep18]$ grep "#.*#9.#" mru
678522#89#98#92
670242#89#97#99
661822#78#94#91
3.
Write a command to display the employee numbers who have same marks in FA1
cut -d'#' -f1,2 mru | tail -6 | sort -nk2 -t'#' | uniq -s7 -D
iV)
Display the employee numbers who got maximum marks in FA1 and FA3
[tr1159773@MYSUL01K sep18]$ sort -nk2 -t'#' mru -r| sort -nk4 -t'#' mru -r
670242#89#97#99
678522#89#98#92
661822#78#94#91
641357#67#75#78
706209#67#34#65
[tr1159773@MYSUL01K sep18]$ sort -nk2 -t'#' mru -r| sort -nk4 -t'#' mru -r |head -1
670242#89#97#99
[tr1159773@MYSUL01K sep18]$ sort -nk2 -t'#' mru -r| sort -nk4 -t'#' mru -r |head -1 | cut -d '#' -f1
670242
[tr1159773@MYSUL01K sep18]$
Display the employee details - Employee Number and FA1 marks who has the least marks in FA1
[tr1159773@MYSUL01K sep18]$ grep "#`cut -d'#' -f2 mru | sort -nk2 -t'#' |head -1`" mru | cut -d"#" -f1,2
641357#67
706209#67
egrep ".*#`cut -d'#' -f2 mru | sort -nk2 -t'#' | uniq -D`" mru
egrep ".*#` sort -nk2 -t'#' mru | cut -d'#' -f2 | uniq -D`" mru
Display the employee details - Employee Number and FA2 marks who has the 3rd maximum marks in FA2
[tr1159773@MYSUL01K sep18]$ sort -nk3 -t'#' mru -r
678522#89#98#92
670242#89#97#99
661822#78#94#91
641357#67#75#78
706209#67#34#65
[tr1159773@MYSUL01K sep18]$ sort -nk3 -t'#' mru -r|head -3 |cut -d '#' -f1,3
678522#98
670242#97
661822#94
[tr1159773@MYSUL01K sep18]$ sort -nk3 -t'#' mru -r|head -3 |cut -d '#' -f1,3| tail -1
661822#94
[tr1159773@MYSUL01K sep18]$|
V)
EmpID:Name:Designation:UnitName:Location:DateofJoining:Salary
1001:Thomson:SE:IVS:Mumbai:10-Feb-1999:60000
1002:Johnson:TE::Bangalore:18-Jun-2000:50000
1003:Jackson:DM:IMS:Hyderabad:23-Apr-1985:90000
1004:BobGL::ETA:Mumbai:05-Jan-2004:55000
1005:Alice:PA:::26-Aug-2014:25000
1006:LilySE:IVS::Bangalore:17-Dec-2015:40000
1007:Kirsten:PM:IMS:Mumbai:26-Aug-2014:45000
1004:BobGL::ETA:Mumbai:05-Jan-2021:55000
List only the employee names working in unit "ETA"
[tr1159773@MYSUL01K sep18]$ grep -i "eta" emp
1004:BobGL::ETA:Mumbai:05-Jan-2004:55000
1004:BobGL::ETA:Mumbai:05-Jan-2021:55000
List only the employee IDs and Names working as "SE"
[tr1159773@MYSUL01K sep18]$ grep -i ":SE:" emp| cut -d ":" -f1,3
1001:SE
List all the employee IDs who have joined in year 2018
[tr1159773@MYSUL01K sep18]$ grep -i "2018:" emp| cut -d ":" -f1
[tr1159773@MYSUL01K sep18]$
List all the employee IDs whose Unit name begins or ends with 'S'
[tr1159773@MYSUL01K sep18]$ cut -d':' -f1,4 emp1 |egrep -i "S$|:S"
1001:SIVS
1003:IMS
1005:Sfe
1007:IMS
[tr1159773@MYSUL01K sep18]$ cut -d':' -f1,4 emp1 |egrep -i "S$|:S"| cut -d':' -f1
1001
1003
1005
1007
Display the count of employees working for 'IMS' unit
[tr1159773@MYSUL01K sep18]$ grep -ic "IMS" emp
2
Display the Employee details of all those working in a location which has 'a' in its location name
[tr1159773@MYSUL01K sep18]$ grep -v "Name" emp|egrep "`cut -d':' -f5 emp|grep 'a'`"
1001:Thomson:SE:IVS:Mumbai:10-Feb-1999:60000
1002:Johnson:TE::Bangalore:18-Jun-2000:50000
1003:Jackson:DM:IMS:Hyderabad:23-Apr-1985:90000
1004:BobGL::ETA:Mumbai:05-Jan-2004:55000
1006:LilySE:IVS::Bangalore:17-Dec-2015:40000
1007:Kirsten:PM:IMS:Mumbai:26-Aug-2014:45000
1004:BobGL::ETA:Mumbai:05-Jan-2021:55000
Display the Employee details of all those working in a location which ends with 'ore' in its location name
[tr1159773@MYSUL01K sep18]$ grep -v "Name" emp|egrep "`cut -d':' -f5 emp|grep 'ore$ '`"
1002:Johnson:TE::Bangalore:18-Jun-2000:50000
1006:LilySE:IVS::Bangalore:17-Dec-2015:40000
Count the number of blank records in the file
[tr1159773@MYSUL01K sep18]$ grep "::" -c emp
5
List only the employee names for whom the unit details are blank
[tr1159773@MYSUL01K sep18]$ grep '.*:.*:.*::' emp |cut -d':' -f2
Johnson
Alice
LilySE
[tr1159773@MYSUL01K sep18]$ cut -d':' -f2,4 emp| grep ":$" | cut -d':' -f1
Johnson
Alice
LilySE
[tr1159773@MYSUL01K sep18]$ cut -d':' -f2,4 emp| grep ":$"
Johnson:
Alice:
LilySE:
[tr1159773@MYSUL01K sep18]$ cut -d':' -f2,4 emp
Name:UnitName
Thomson:IVS
Johnson:
Jackson:IMS
BobGL:ETA
Alice:
LilySE:
Kirsten:IMS
BobGL:ETA
[tr1159773@MYSUL01K sep18]$
List employee IDs and designation for employees who are not working as "PA"
[tr1159773@MYSUL01K sep18]$ grep -v '.*:.*:PA:' emp
EmpID:Name:Designation:UnitName:Location:DateofJoining:Salary
1001:Thomson:SE:IVS:Mumbai:10-Feb-1999:60000
1002:Johnson:TE::Bangalore:18-Jun-2000:50000
1003:Jackson:DM:IMS:Hyderabad:23-Apr-1985:90000
1004:BobGL::ETA:Mumbai:05-Jan-2004:55000
1006:LilySE:IVS::Bangalore:17-Dec-2015:40000
1007:Kirsten:PM:IMS:Mumbai:26-Aug-2014:45000
1004:BobGL::ETA:Mumbai:05-Jan-2021:55000
[tr1159773@MYSUL01K sep18]$ grep -v '.*:.*:PA:' emp |cut -d ":" -f1,3
EmpID:Designation
1001:SE
1002:TE
1003:DM
1004:
1006:IVS
1007:PM
1004:
Count all the employees working in 'Mumbai' location
[tr1159773@MYSUL01K sep18]$ grep -ic "mumbai" emp
4
Display all employees who have joined in current year
[tr1159773@MYSUL01K sep18]$ grep `date +%Y` emp
1004:BobGL::ETA:Mumbai:05-Jan-2021:55000
EmpID:Name:Designation:UnitName:Location:DateofJoining:Salary
1001:Thomson:SE:SIVS:Mumbai:10-Feb-1999:60000
1002:Johnson:TE::Bangalore:18-Jun-2000:50000
1003:Jackson:DM:IMS:Hyderabad:23-Apr-1985:90000
1004:BobGL::ETA:Mumbai:05-Jan-2004:55000
1005:Alice:PA:Sfe::26-Aug-2014:25000
1006:LilySE:IVS::Bangalore:17-Dec-2015:40000
1007:Kirsten:PM:IMS:Mumbai:26-Aug-2014:45000
1004:BobGL::ETA:Mumbai:05-Jan-2021:55000