0% found this document useful (1 vote)
5K views

Unix Codes

Abc

Uploaded by

aryakaagnihotri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
5K views

Unix Codes

Abc

Uploaded by

aryakaagnihotri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Practice1_Unix_Java_1st_Feb_24_KOL  4792678_857_25872656@tcsltd.

com

You can view this report online at : https://www.hackerrank.com/x/tests/1836553/candidates/60823202/report

Full Name: Soumyajit Biswas


scored in
Email: 4792678_857_25872656@tcsltd.com
100% Practice1_Unix_Java_1st_Feb_24_KOL
Test Name: Practice1_Unix_Java_1st_Feb_24_KOL in 128 min 51 sec on 20 Feb 2024
410/410 10:54:54 IST
Taken On: 20 Feb 2024 10:54:54 IST

Time Taken: 128 min 51 sec/ 10000 min

Employee Id: 2476889

Floor: 2

TR: 5

Building: 1B

Invited by: Velantish

Invited on: 20 Feb 2024 10:54:16 IST

Skills Score:

Tags Score: Bash 290/290

Easy 100/100
Medium 75/75

UNIX Programming 60/60

Unix 320/320
coding 100/100

programming 30/30
simple 100/100

Recruiter/Team Comments:

No Comments.

Question Description Time Taken Score Status

Q1 Retrieve student info based on marks  Coding 2 min 7 sec 15/ 15 


Q2 Unix FindTotalCount  Coding 7 min 3 sec 15/ 15 
Q3 PRA_Unix_Fruits  Coding 2 min 20 sec 15/ 15 
Q4 Unix : Print Order total  Coding 5 min 4 sec 15/ 15 
Q5 PRA2-3rd_Feb-Unix - Fetch Students  Coding 8 min 52 sec 15/ 15 
Q6 Unix : Replace Word  Coding 2 min 12 sec 100/ 100 
Q7 Unix : Word Count  Coding 7 min 21 sec 100/ 100 
1/21
Q8 UNIX_Doctor_Updated  Coding 28 min 51 sec 15/ 15 
Q9 OS After Change  Coding 10 min 21 sec 15/ 15 
Q10 Find Hospital with capacity  Coding 4 min 38 sec 15/ 15 
Q11 PRA Unix SBQ Sanitizer_2023  Coding 1 min 57 sec 15/ 15 
Q12 2023_Unix_EV_Cars  Coding 29 min 25 sec 15/ 15 
Q13 SoapManagement_Unix_PRA  Coding 2 min 47 sec 15/ 15 
Q14 Find Count of Employee with the department  Coding 1 min 50 sec 15/ 15 
Q15 unix pra jp-employee  Coding 1 min 14 sec 15/ 15 
Q16 PRA Unix : Medicine  Coding 12 min 31 sec 15/ 15 

QUESTION 1 Retrieve student info based on marks 



Coding Unix UNIX Programming

Correct Answer
QUESTION DESCRIPTION

Contents of the file studentinfo.txt are as follow:


Score 15
StudentId|StudentName|StudentScore
1|sahil|60
2|sid|70
3|Dave|50
4|Roy|90

Fields are seperated by "|"

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 0 Easy Sample case  Success 3.75 0.0061 sec 1.73 KB

Testcase 1 Easy Sample case  Success 3.75 0.0018 sec 1.78 KB

Testcase 2 Easy Hidden case  Success 3.75 0.0035 sec 1.74 KB

Testcase 3 Easy Hidden case  Success 3.75 0.002 sec 1.72 KB

No Comments

QUESTION 2 Unix FindTotalCount 



Coding Bash Unix

Correct Answer
QUESTION DESCRIPTION

Store Sales details are stored in a file in the following format separated by one blank space.
Score 15

SName Location Product Count

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.

Note : the search for product should be case insensitive.

Example 1:
Input:

SName Location Product Count


BigBazaar Delhi Smartphone 25
Chroma Mumbai Television 45
Flipkart Kolkata WashingMachine 29

3/21
Amazon Kolkata DSLRCamera 65
Amazon Delhi Television 24

Output :
Total Count = 25

Example 2:
Input:

SName Location Product Count


BigBazaar Delhi Mouse 25
Chroma Mumbai Headphone 5
Flipkart Kolkata AC 49
Amazon Kolkata DSLRCamera 65
Amazon Delhi Laptop 67

Output:
No Smartphone Product found.

CANDIDATE ANSWER

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 0 Easy Sample case  Success 2 0.003 sec 1.75 KB

Testcase 1 Easy Sample case  Success 3 0.0032 sec 1.78 KB

Testcase 2 Easy Hidden case  Success 5 0.0026 sec 1.75 KB

Testcase 3 Easy Hidden case  Success 5 0.0023 sec 1.75 KB

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

Language used: BASH

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

Sample 1 Easy Sample case  Success 2 0.0025 sec 1.8 KB

Sample 2 Easy Sample case  Success 3 0.0031 sec 1.79 KB

Testcase 1 Easy Hidden case  Success 5 0.0025 sec 1.77 KB

Testcase 2 Easy Hidden case  Success 5 0.0024 sec 1.76 KB

No Comments

QUESTION 4 Unix : Print Order total 



Coding Bash Medium

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

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Sample 1 Easy Sample case  Success 4 0.0026 sec 1.76 KB

Testcase 1 Medium Hidden case  Success 5 0.0022 sec 1.74 KB

Testcase 2 Easy Hidden case  Success 6 0.0025 sec 1.76 KB

No Comments

QUESTION 5 PRA2-3rd_Feb-Unix - Fetch Students 



Coding Bash Medium

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

Fields are separated by the field separator ("|")

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

Language used: BASH

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 "|"

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 0 Easy Sample case  Success 2 0.0047 sec 1.8 KB

Testcase 1 Easy Hidden case  Success 3 0.0024 sec 1.8 KB

Testcase 2 Easy Hidden case  Success 5 0.003 sec 1.74 KB

Testcase 3 Easy Hidden case  Success 5 0.0089 sec 1.77 KB

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,

If the input file contains the following lines

Unix is an multi-user,multi-tasking system.


It is a command based operating system.
We will learn unix in this module.

The output should be

Unix OS is an multi-user,multi-tasking system.


It is a command based operating system.
We will learn Unix OS in this module.

CANDIDATE ANSWER

Language used: BASH

1 awk '
2 BEGIN{IGNORECASE=1}
3 {
4 gsub("Unix", "Unix OS");
5 print;
6 }
7 END{}
8 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 1 Easy Sample case  Success 10 0.0022 sec 1.75 KB

Testcase 2 Easy Hidden case  Success 30 0.003 sec 1.74 KB

Testcase 3 Easy Hidden case  Success 30 0.0072 sec 1.72 KB

Testcase 4 Easy Hidden case  Success 30 0.0034 sec 1.79 KB

No Comments

QUESTION 7 Unix : Word Count 



Coding Unix Bash Easy

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

Unix is a command based operating system.


We will learn unix in this module.
This is a test file.
We are using this file to practice some commands.
We have reached the end of the file.

The output will be,


19

CANDIDATE ANSWER

Language used: BASH

1 head -3 | wc -w

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Sample 1 Easy Sample case  Success 10 0.0034 sec 1.81 KB

Sample Easy Sample case  Success 10 0.0023 sec 1.83 KB

Testcase 1 Easy Hidden case  Success 40 0.0028 sec 1.77 KB

Testcase 2 Easy Hidden case  Success 40 0.0018 sec 1.79 KB

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

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 0 Easy Sample case  Success 5 0.0025 sec 1.73 KB

Testcase 1 Easy Hidden case  Success 5 0.0017 sec 1.75 KB

Testcase 2 Easy Hidden case  Success 5 0.0028 sec 1.82 KB

No Comments

QUESTION 9 OS After Change 



Coding

Correct Answer QUESTION DESCRIPTION

Operating system details are stored in a file in the given format:


Score 15

Serial_No OS_Name Version


1 Windows 10
2 Linux 8
3 RedHat 5

Fields are separated by the default field separator (blank space)

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.

Note: The search of the string should be case insensitive.

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:

Serial_No OS_Name Version


1 Windows 10
2 Linux 8
3 RedHat 5
4 Windows 9
6 linux 3
7 RedHat 4

Output:

Serial_No OS_Name Version


1 RedHat 10
2 Linux 8
4 RedHat 9

CANDIDATE ANSWER

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 0 Easy Sample case  Success 3 0.0032 sec 1.79 KB

Testcase 1 Easy Hidden case  Success 4 0.0064 sec 1.77 KB

Testcase 2 Easy Hidden case  Success 4 0.0046 sec 1.75 KB

12/21 
Testcase 3 Easy Hidden case  Success 4 0.0051 sec 1.78 KB

No Comments

QUESTION 10 Find Hospital with capacity 



Coding Unix UNIX Programming

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

Language used: BASH

1 awk '
2 BEGIN{FS="|"; IGNORECASE=1}
3 {
4 if($3>1200)
5 {
6 print;
7 }
8 }
9 END{}
10 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 0 Easy Sample case  Success 3.75 0.0019 sec 1.75 KB

Testcase 1 Easy Sample case  Success 3.75 0.003 sec 1.83 KB

Testcase 2 Easy Hidden case  Success 3.75 0.0031 sec 1.78 KB


13/21
Testcase 3 Easy Hidden case  Success 3.75 0.0027 sec 1.75 KB

No Comments

QUESTION 11 PRA Unix SBQ Sanitizer_2023 



Coding Unix programming

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:

Total count: <count>

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

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED


14/21
Testcase 0 Easy Sample case  Success 3 0.002 sec 1.72 KB

Testcase 1 Easy Sample case  Success 2 0.0022 sec 1.77 KB

Testcase 2 Easy Hidden case  Success 5 0.0948 sec 1.74 KB

Testcase 3 Easy Hidden case  Success 5 0.0034 sec 1.74 KB

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

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 1 Easy Sample case  Success 3 0.0022 sec 1.77 KB

Testcase 2 Easy Sample case  Success 3 0.0016 sec 1.79 KB

Testcase 3 Easy Hidden case  Success 4 0.0029 sec 1.79 KB

Testcase 4 Easy Hidden case  Success 5 0.0016 sec 1.77 KB

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:

Total count: <count>

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 :

No soap found with cost above 300

CANDIDATE ANSWER

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

17/21
Testcase 0 Easy Sample case  Success 3.5 0.0019 sec 1.75 KB

Testcase 1 Easy Sample case  Success 3.5 0.0019 sec 1.84 KB

Testcase 2 Easy Hidden case  Success 4 0.0019 sec 1.77 KB

Testcase 3 Easy Hidden case  Success 4 0.0024 sec 1.79 KB

No Comments

QUESTION 14 Find Count of Employee with the department 



Coding Unix UNIX Programming

Correct Answer
QUESTION DESCRIPTION

Consider the following file


Score 15
EmployeeId|EmployeeName|DeptId
1|sahil|IT
2|sid|HR
3|Dave|IT
4|Roy|Facilitation

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

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Testcase 0 Easy Sample case  Success 3.75 0.0017 sec 1.77 KB


18/21
Testcase 1 Easy Sample case  Success 3.75 0.0025 sec 1.82 KB

Testcase 2 Easy Hidden case  Success 3.75 0.0021 sec 1.79 KB

Testcase 3 Easy Hidden case  Success 3.75 0.0019 sec 1.76 KB

No Comments

QUESTION 15 unix pra jp-employee 



Coding Unix UNIX Programming

Correct Answer
QUESTION DESCRIPTION

Consider the following file


Score 15
EmployeeId|EmployeeName|DeptId
1|sahil|IT
2|sid|HR
3|Dave|IT
4|Roy|Facilitation

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

Language used: BASH

1 awk '
2 BEGIN{FS="|"; IGNORECASE=1}
3 {
4 if($3=="IT")
5 {
6 print;
7 }
8 }
9 END{
10 }
11 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

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

Testcase 1 Easy Sample case  Success 3.75 0.0022 sec 1.76 KB

Testcase 2 Easy Hidden case  Success 3.75 0.0038 sec 1.72 KB

Testcase 3 Easy Hidden case  Success 3.75 0.0017 sec 1.8 KB

No Comments

QUESTION 16 PRA Unix : Medicine 



Coding Bash Medium

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

There are 3 fields in the file separated by ",".


First field is Medicine ID, second is Medicine name and then Medicine cost. The
medicine ID is having format like <type of medicine>_<unique medicine ID
1. For Spray type, medicine type is denoted by "SP"(any case, upper or lower) and
tagged with a unique medicine ID of 6 digit number prefixed by "_". eg: SP_123423
2. For Tablet type, medicine type is denoted by "TB"(any case, upper or lower) and
tagged with unique medicine ID prefixed with "_". This medicine ID is a combination
of unique ID and number of tablet in a strip. The number of tablet is also prefixed
with a "_". Eg: TB_986656_10
Write the UNIX command to print the medicine IDs of all Tablet medicines with
number of tablets per strip greater than 10.
If no tablet medicine with number of tablet greater than 10 present in the input file,
then print "No medicines found with greater than 10 numbers in a strip" (without the
quotes)
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.
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

Language used: BASH

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 '

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

Sample 1 Easy Sample case  Success 4 0.0059 sec 1.75 KB

Testcase 1 Medium Hidden case  Success 5 0.0018 sec 1.76 KB

Testcase 2 Easy Hidden case  Success 6 0.0024 sec 1.76 KB

No Comments

PDF generated at: 20 Feb 2024 07:35:33 UTC

21/21

You might also like