top of page

OPA May 22 Unix 

Write the unix commands in the editor, displayed beside the Question text to do the following:

​

1. Read an input string (line of words from the 'testcase input' / 'custome input') and store it in a variable using read statement.

2. Count the number of words and number of characters in the string.

3. Find and display the average number of characters per word in the string.

 

The average number of words can be calculated as :

Average no. of charecters per word = Total number of characters / Total number of words.

 

Note : Decimals need not be considered in the division. e.g. If result is 7.62, we will consider result as 7.

 

For more details, please refer to the sample input and output below.

 

Input Format    words in the box used for tom Testing.

The string entered in the text field under 'custom input' option or the string from the testcase input will be supplied as input to shell script.

To test your code with custom input option the respective checkbox needs to be enabled to enter the line of words in the text field .

 

Intruction to read testcase input OR to read from custom input text field:

The input string in the text field of custom input option or the test case input will be supplied to a variable, which is being used in the read statement, to be written by you . Hence  write the read statement as first statement in the script to store the test case input or custom input data into any variable. Use the variable for further processing as per the given requirement.

​

​

Sample test case

​

test case Input:

Welcome to this tutorial on Unix where we are practicing some commands

 

test case output:

5

​

Solutions:

​

​

readarray f
first=$(echo $f |wc -w )
second=$(echo $f | wc -c )
k=$(( second/first ))
echo $k

​

Try in online compiler -> click here

(COPY THE INPUT AND PASTE IT IN STDIN OF COMPILER)

Know your TCS: Services

©2018 by The real one. Proudly created with Wix.com

bottom of page