Unix Codes
Unix Codes
com
Floor: 2
TR: 5
Building: 1B
Skills Score:
Easy 100/100
Medium 75/75
Unix 320/320
coding 100/100
programming 30/30
simple 100/100
Recruiter/Team Comments:
No Comments.
Correct Answer
QUESTION DESCRIPTION
Write a command to retrive the information of the student whose marks are more than 50. In the format of
StudentId|StudentName|StudentScore. If none of the students have marks more than 50, dont display
anything on the screen.
The input file with the data (testcase input / customized input) in the format mentioned, automatically
supplied as command line argument when you run the script / command, you have written. Hence you don't
need to worry / work on, " How to bring the file to your script"?
You just need to assume that a file is supplied to your script and read the file, which is supplied as command
line argument and process the data in the file towards the given requirement.
You can use shell variables (e.g., $0, $1, $2) whichever is applicable for your requirement to provide the
command line argument.
Sample Input:
1|sahil|60
2|sid|70
3|Dave|50
4|Roy|90
Sample output:
1|sahil|60
2|sid|70
4|Roy|90
CANDIDATE ANSWER
2/21
Language used: BASH
1 awk '
2 BEGIN{FS="|"}
3 {
4 if($3>50)
5 {
6 print;
7 }
8 }
9 END{}
10 '
No Comments
Correct Answer
QUESTION DESCRIPTION
Store Sales details are stored in a file in the following format separated by one blank space.
Score 15
Write the unix command to find the total count of the Smartphone product listed in details .
The output should be as below:
Total Count = <the value calculated>
In case there are no records found for Smartphone product, the output should be "No
Smartphone Product found." excluding the quotes.
Refer the example below for more clarity on input and output format.
The file name input will be provided as command line argument when the script containing
your command will run.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to
provide the command line argument.
Example 1:
Input:
3/21
Amazon Kolkata DSLRCamera 65
Amazon Delhi Television 24
Output :
Total Count = 25
Example 2:
Input:
Output:
No Smartphone Product found.
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS=" "; c=0; IGNORECASE=1}
3 {
4 if($3 == "Smartphone")
5 {
6 c += $4;
7 }
8 }
9 END{
10 if(c==0)
11 {
12 print("No Smartphone Product found.")
13 }
14 else
15 {
16 print("Total Count =", c)
17 }
18 }
19 '
No Comments
QUESTION 3 PRA_Unix_Fruits
Coding Bash Medium
QUESTION DESCRIPTION
4/21
QUESTION DESCRIPTION
The file Fruits.txt contains following data in the order fruitName,fruitType,pricePerUnit. The
Correct Answer fields are separated by a comma (“,”).
Score 15 Mango,Langda,40
Mango,Alphanso,100
Apple,Kashmiri,130
Banana,robusta,30
Banana,Red,35
Write the Unix command to print the count of fruits whose price per unit is greater than 100.
Print the output in below format
Total count: <count>
Note: In case there are no records fulfilling the given condition, print the total count is 0.
The file name input will be provided as command line argument when the script containing your command
will run.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to provide the
command line argument.
For more clarity, please refer to the sample input and output below.
Sample Input 1 :
Mango,Langda,40
Mango,Alphanso,120
Apple,Kashmiri,130
Banana,robusta,30
Banana,Red,35
Output :
Total count: 2
Sample Input 2 :
Mango,Langda,70
Mango,Alphanso,140
Apple,Kashmiri,130
Banana,robusta,30
Apple,Shimla,62
Apple,Fuji,160
Output :
Total count: 3
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS=","; IGNORECASE=1; c=0}
3 {
4 if($3>100)
5 {
6 c += 1;
7 }
8 }
9 END{
10 print ("Total count:", c);
11 }
12 '
5/21
TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED
No Comments
Correct Answer
QUESTION DESCRIPTION
You have a file having order amount details of customers for orders placed. The format of the file is as
Score 15
below ('-' is the field delimeter):
CustId-Order1-Order2-Order3
C101-55-12-12
C234-67-42-13
C341-90-90-90
C511-40-40-40
Write the Unix command to print the record of those Customers whose total order amount is >=200.
i.e. the summation of order1,order2,order3 is greater than equal to 200. Also print the total count of
such customers at the end as "Total:" without the quotes. Please refer to the sample output.
The file name will be provided as a command line argument when the script containing your command will
run.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to provide the
command line argument.
For more clarity on inputs and outputs, please refer to the sample input and output below.
Note: In case there are no records fulfilling the given condition, just print the total count value as 0.
Sample Input 1 :
CustID-Order1-Order2-Order3
C101-55-12-12
C234-67-42-13
C341-90-90-90
C511-40-40-40
Output :
C341-90-90-90
Total: 1
Sample Input 2 :
CustID-Order1-Order2-Order3
C101-55-12-12
C234-67-42-13
C341-13-10-90
C511-41-40-40
Output :
6/21
Total: 0
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="-"; IGNORECASE=1, count=0}
3 {
4 if($2+$3+$4 >= 200)
5 {
6 count+=1;
7 print;
8 }
9 }
10 END{print("Total: ", count)}
11 '
No Comments
Correct Answer
QUESTION DESCRIPTION
Score 15
Contents of intput file: studentsData
StudentNo|Name|Standard|SchoolName|MathematicsScore|ScienceScore
1|Latha|Third|Vikas|90|91
2|Neethu|Second|Meridian|92|94
3|Sethu|First|DAV|86|98
4|Theekshana|Second|DAV|97|86
5|Teju|First|Sangamithra|89|88
6|Theekshitha|Second|Sangamithra|99|100
Write a command to fetch the student details , who scored >=90 in mathematics and >=90 in Science
subject from Sangamithra school and display students details.
The display record format is:
StudentNo,Name,Standard,SchoolName and Average of Marks(of two subjects given in th input data ) of the
students in the Ascending order of the average of the scores, if there are multiple records satisfies the given
condition. If no records satisfies the given condition then output is empty.
For more clarity, please refer to the sample testcase input and output below.
7/21
The input file with the data(testcase input / customized input) in the format mentioned, automatically
supplied as command line argument when you run the script / command , you have written. Hence you don't
need to worry / work on, " How to bring the file to your script"?.
You just need to assume that a file is supplied to your script and read the file, which is supplied as command
line argument and process the data in the file towards the given requirement.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to provide the
command line argument.
Sample Testcase:
Input:
1|Latha|Third|Vikas|90|91
2|Neethu|Second|Meridian|92|94
3|Sethu|First|DAV|86|98
4|Theekshana|Second|DAV|97|86
5|Teju|First|Sangamithra|92|94
6|Theekshitha|Second|Sangamithra|99|100
Output:
5|Teju|First|Sangamithra|93
6|Theekshitha|Second|Sangamithra|99.5
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="|"; OFS="|"; IGNORECASE=1}
3 {
4 if($4=="Sangamithra" && $5>=90 && $6>=90)
5 {
6 avg = ($5+$6)/2;
7 print ($1,$2,$3,$4,avg);
8 }
9 }
10 END{
11
12 }
13 ' | sort -k5n -t "|"
No Comments
8/21
QUESTION 6 Unix : Replace Word
Coding Unix Bash coding simple
Correct Answer
QUESTION DESCRIPTION
Write the unix command to replace the word "Unix" with "Unix OS" in a given file.
Score 100
The file will be given as a command line argument when the script containing your command will run.
Note : The search for "Unix" to replace with "Unix OS" should be case-insensitive.
For example,
CANDIDATE ANSWER
1 awk '
2 BEGIN{IGNORECASE=1}
3 {
4 gsub("Unix", "Unix OS");
5 print;
6 }
7 END{}
8 '
No Comments
Correct Answer
QUESTION DESCRIPTION
Write the unix command to count the number of words in the first 3 lines of a file.
Score 100
The file will be given as a command line argument when the script containing your command will run.
9/21
For example,
If the input file contains the following lines
CANDIDATE ANSWER
1 head -3 | wc -w
No Comments
QUESTION 8 UNIX_Doctor_Updated
Coding Unix
Correct Answer
QUESTION DESCRIPTION
You have a file-Doctor which stores doctor details. File contains ID, Name, Age and Salary separated by
Score 15
hyphen ('-' is the field separator) :
D101-Hema-22-40000
D234-Teja-24-50000
D341-Rama-25-70000
D511-Raju-27-27000
Write the Unix command to print the total count of such Doctors whose salary is greater than 50000 as
"Total<space>:<space>the count value" without the quotes. Please refer to the sample output.
The file name will be provided as a command line argument when the script containing your command will
run.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to provide the
command line argument.
For more clarity on inputs and outputs, please refer to the sample input and output below.
Note: In case there are no records fulfilling the given condition, just print the total count value as 0.
Sample Input 1 :
01-Hema-22-40000
D234-Teja-24-50000
10/21
D341-Rama-45-70000
D511-Raju-47-97000
Output :
Total : 2
Sample Input 2 :
D101-Lakshmi-22-10000
D234-Dharani-24-40000
D341-Durga-25-30000
D511-Chanakya-27-27000
output:
Total : 0
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="-"; IGNORECASE=1; c=0}
3 {
4 if($4>50000)
5 {
6 c+=1;
7 }
8 }
9 END{print("Total : " c)}
10 '
No Comments
Write the command or script to replace the OS name for windows and RedHat to RedHat and windows
respectively first and then display only the OS records whose version is more than 7.
11/21
For more clarity, please refer to the sample input and output below.
The input file with the data(testcase input / customized input) in the format mentioned, automatically
supplied as command line argument when you run the script / command , you have written. Hence you don't
need to worry / work on, " How to bring the file to your script"?.
You just need to assume that a file is supplied to your script and read the file, which is supplied as command
line argument and process the data in the file towards the given requirement.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to provide the
command line argument.
Input:
Output:
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS=" "}
3 {
4 if($2=="Windows")
5 {
6 gsub("Windows", "RedHat")
7 }
8 if($2=="RedHat")
9 {
10 gsub("RedHat", "windows")
11 }
12 if($3>7)
13 {
14 print;
15 }
16 }
17 END{}
18 '
12/21
Testcase 3 Easy Hidden case Success 4 0.0051 sec 1.78 KB
No Comments
Correct Answer
QUESTION DESCRIPTION
Score 15
Consider the following hospital.txt
hospitalId|hospitalName|capacity
1|LG|1200
2|HCG|1500
3|Apollo|1300
4|Sunflower|1000
You need to write a command to print only the hospital id whose capacity is more than 1200. If there is no
hospital with the mentioned name you not be printing anything.
The input file with the data (testcase input / customized input) in the format mentioned, automatically
supplied as command line argument when you run the script / command, you have written. Hence you don't
need to worry / work on, " How to bring the file to your script"?
You just need to assume that a file is supplied to your script and read the file, which is supplied as command
line argument and process the data in the file towards the given requirement.
You can use shell variables (e.g., $0, $1, $2) whichever is applicable for your requirement to provide the
command line argument.
Sample input:
1|LG|1200
2|HCG|1500
3|Apollo|1300
4|Sunflower|1000
Sample output:
2|HCG|1500
3|Apollo|1300
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="|"; IGNORECASE=1}
3 {
4 if($3>1200)
5 {
6 print;
7 }
8 }
9 END{}
10 '
No Comments
Correct Answer
QUESTION DESCRIPTION
You have a file having Sanitizer details with fields as ID,Name,stock,price . The fields are separated by # ('#'
Score 15
is the field delimiter):
S210#dettol#22#400
S330#Godrej#24#500
S440#Lifebuoy#25#700
S550#savlon#27#270
Write a Unix command to count the number of sanitizer records with a price greater than 300. Print output in
the following format:
The file name will be provided as a command-line argument when the script containing your command will
run.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to providing the
command line argument.
For more clarity on inputs and outputs, please refer to the sample input and output below.
Note: In case there are no records fulfilling the given condition, just print the total count value is 0.
Sample Input 1 :
S210#dettol#22#400
S330#Godrej#24#500
S440#Lifebuoy#25#700
S550#savlon#27#270
Output :
Total count: 3
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="#"; IGNORECASE=1; c=0}
3 {
4 if($4>300)
5 {
6 c+=1;
7 }
8 }
9 END{print("Total count: " c)}
10 '
No Comments
QUESTION 12 2023_Unix_EV_Cars
Coding Bash Medium
Correct Answer
QUESTION DESCRIPTION
Write the Unix command to display the number of cars who are belonging to car company named Tata
Score 15
Motors and Model Type is EV
The details of the cars are stored in a file(inputfile) in the following format.
CarId*ModelName*CarCompany*ModelType
where symbol '*' is used as the field delimiter for the file.
If there is no record in input file or no records satisfying the above criteria, print "No records found".
The file name will be provided as command line argument when the script containing your command will
run.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to provide the
command line argument.
For more clarity, please refer to the sample input and output below.
Note: The string values for CarCompany and ModelType can be in any case, hence search should be
case insensitive.
Sample Input 1 :
CarId*ModelName*CarCompany*ModelType
1*Tata Punch*Tata Motors*Petrol
2*Tata Nexon*Tata Motors*ev
3*Tigor*Tata Motors*EV
4*i10*Hyundai*Petrol
5*i20*Hyundai*Petrol
Output :
2
Sample Input 2 :
CarId*ModelName*CarCompany*ModelType
1*Tata Punch*Tata Motors*Petrol
2*Tata Nexon*Tata Motors*Petrol
3*Tigor*Tata Motors*Petrol
4*i10*Hyundai*Petrol
5*i20*Hyundai*Petrol
Output :
No records found
15/21
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="*"; IGNORECASE=1; c=0}
3 {
4 if($4=="ev")
5 {
6 c+=1;
7 }
8 }
9 END{
10 if(c==0)
11 {
12 print("No records found");
13 }
14 else
15 {
16 print(c)
17 }
18 }
19 '
No Comments
QUESTION 13 SoapManagement_Unix_PRA
Coding Unix programming
Correct Answer
QUESTION DESCRIPTION
You have a file having Soap details. The format of the file is as below ('#' is the field delimiter):
Score 15
ID#Name#Quantity#Price
S101#lux#22#40
S234#liril#24#50
S341#mCaffeine#25#301
S511#Truefit#27#800
Write a Unix command to print the total quantity of soaps with price greater than 300. Print output in the
following format:
If there are no soaps with a price of more than 300, then print "No soap found with cost above 300"
(excluding the quotes).
The file name will be provided as a command line argument when the script containing your command will
run.
16/21
You can use shell variables (e.g. $0,$1,$2) whichever is applicable to your requirement to provide the
command line argument.
For more clarity on inputs and outputs, please refer to the sample input and output below.
Sample Input 1 :
ID#Name#Quantity#Price
S101#lux#22#40
S234#liril#24#50
S341#mCaffeine#25#301
S511#Truefit#27#800
Output :
Total count: 52
Sample Input 2 :
ID#Name#Quantity#Price
S101#lux#22#40
S234#liril#24#50
S341#mCaffeine#25#300
S511#Truefit#27#299
Output :
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="#"; IGNORECASE=1; c=0}
3 {
4 if($4>300)
5 {
6 c+=$3;
7 }
8 }
9 END{
10 if(c==0)
11 {
12 print("No soap found with cost above 300")
13 }
14 else
15 {
16 print("Total count: " c);
17 }
18 }
19 '
17/21
Testcase 0 Easy Sample case Success 3.5 0.0019 sec 1.75 KB
No Comments
Correct Answer
QUESTION DESCRIPTION
You need to write a command so that you can print the number of the employees with the IT as the
department. If there is no employee with the mentioned Dept print 0
The file name input will be provided as command line argument when the script containing your command
will run.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to provide the
command line argument.
For more clarity, please refer to the sample input and output below.
Sample input:
EmployeeId|EmployeeName|DeptId
1|sahil|IT
2|sid|HR
3|Dave|IT
4|Roy|Facilitation
Sample output:
2
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="|"; IGNORECASE=1; c=0}
3 {
4 if($3=="IT")
5 {
6 c+=1;
7 }
8 }
9 END{
10 print(c);
11 }
12 '
No Comments
Correct Answer
QUESTION DESCRIPTION
You need to write a command so that you can print the only the rows of the Employees who are in the IT. If
there are no records related to "IT", dont print anything.
The file name input will be provided as command line argument when the script containing your command
will run.
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your requirement to provide the
command line argument.
For more clarity, please refer to the sample input and output below.
Sample input:
EmployeeId|EmployeeName|DeptId
1|sahil|IT
2|sid|HR
3|Dave|IT
4|Roy|Facilitation
Sample output:
1|sahil|IT
3|Dave|IT
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS="|"; IGNORECASE=1}
3 {
4 if($3=="IT")
5 {
6 print;
7 }
8 }
9 END{
10 }
11 '
19/21
Testcase 0 Easy Sample case Success 3 75 0 0022 sec 1 8 KB
Testcase 0 Easy Sample case Success 3.75 0.0022 sec 1.8 KB
No Comments
Correct Answer
QUESTION DESCRIPTION
Score 15
The Input file with Medicine details having data in following format:
MedicineId,MedicineName,MedicineCost
SP_123423,Montek,75
SP_714441,Forocot,105
TB_006745_10,Concor,250
TB_102030_25,Ivabid,325
TB_100011_15,Zetamit,150
You can use shell variables (e.g. $0,$1,$2) whichever is applicable for your
requirement to provide the command line argument.
Sample 1:
Input:
MedicineId,MedicineName,MedicineCost
SP_123423,Montek,75
SP_714441 ,Forocot,105
TB_006745_10,Concor,250
TB_102030_25,Ivabid,325
20/21
tb_100011_15,Zetamit,150
Output:
TB_102030_25
tb_100011_15
Sample 2:
Input:
MedicineId,MedicineName,MedicineCost
SP_498774,Montek,75
SP_714441,Forocot,105
TB_567775_10,Concor,250
Tb_121234_6,Ivabid,325
tb_123456_5,Zetamit,150
Output:
No medicines found with greater than 10 numbers in a strip
CANDIDATE ANSWER
1 awk '
2 BEGIN{FS=","; IGNORECASE=1}
3 {
4 print($1)
5 }
6 END{}
7 ' | awk '
8 BEGIN{FS="_"; OFS="_"; IGNORECASE=1, c=0}
9 {
10 if($3>10)
11 {
12 print($1, $2, $3);
13 c++;
14 }
15 }
16 END{
17 if(c==0)
18 {
19 print("No medicines found with greater than 10 numbers in a strip");
20 }
21 }
22 '
No Comments
21/21