0% found this document useful (0 votes)
71 views

Linux Hackerrank

Uploaded by

Roopam Seal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Linux Hackerrank

Uploaded by

Roopam Seal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 50

1. Write a bash script that prints the string "HELLO".

2. Your task is to use for loops to display only odd natural numbers from 1
to 99.
3. Write a Bash script which accepts name as input and displays the greeting
"Welcome (name)"
4. Use a for loop to display the natural numbers from 1 to 50.
5. Given two integers, X and Y, find their sum, difference, product, and quotient.
6. Given two integers, X and Y, identify whether X<Y or X>Y or X=Y.
7. Read in one character from STDIN.
If the character is 'Y' or 'y' display "YES".
If the character is 'N' or 'n' display "NO".
No other character will be provided as input.
8. Given three integers (X, Y, and Z) representing the three sides of a
triangle, identify whether the triangle is scalene, isosceles, or
equilateral.
If all three sides are equal, output EQUILATERAL.
Otherwise, if any two sides are equal, output ISOSCELES.
Otherwise, output SCALENE.
9. A mathematical expression containing +,-,*,^, / and parenthesis will be provided.
Read in the expression, then evaluate it. Display the result rounded to 3 decimal
places.
10. Given N integers, compute their average, rounded to three decimal
places.

11. This challenge involves the construction of trees, in the form of ASCII Art.
We have to deal with real world constraints, so we cannot keep
repeating the pattern infinitely. So, we will provide you a number of
iterations, and you need to generate the ASCII version of the Fractal
Tree for only those many iterations (or, levels of recursion). A few
samples are provided below.
12. Given N lines of input, print the 3rd character from each line as a new line
of output. It is guaranteed that each of the n lines of input will have a 3rd
character.
13. Display the 2nd and 7th character from each line of text.
14. Display a range of characters starting at the 2nd position of a string and
ending at the 7th position (both positions included).

15. Display the first four characters from each line of text.
16. Given a tab delimited file with several columns (tsv format) print the first
three fields.
17. Print the characters from thirteenth position to the end.
18. Given a sentence, identify and display its fourth word. Assume that the
space (' ') is the only delimiter between words.
19. Given a sentence, identify and display its first three words. Assume that
the space (' ') is the only delimiter between words.
20. Given a tab delimited file with several columns (tsv format) print the fields
from second fields to last field.
21. In this challenge, we practice using the head command to display the first
n lines of a text file.
22. In this challenge, we practice using the head command to display the first
n characters of a text file.
23. Display the lines (from line number 12 to 22, both inclusive) of a given
text file.
24. In this challenge, we practice using the tail command to display the last n
lines of a text file.
25. In this challenge, we practice using the tail command to display the last n
characters of a text file.
26. In this challenge, we practice using the tr command because it is a useful
translation tool in Linux.
27. In this challenge, we practice using the tr command because it is a useful
translation tool in Linux.

28. In a given fragment of text, replace all sequences of multiple spaces with
just one space.
29. In this challenge, we practice using the sort command to sort input in text
or TSV formats.
30. In this challenge, we practice using the sort command to sort
input in text or TSV formats.
Given a text file, order the lines in reverse lexicographical order (i.e. Z-
A instead of A-Z).
31. In this challenge, we practice using the sort command to sort
input in text or TSV formats.
You are given a text file where each line contains a number. The
numbers may be either an integer or have decimal places. There will
be no extra characters other than the number or the newline at the
end of each line. Sort the lines in ascending order - so that the first line
holds the numerically smallest number, and the last line holds the
numerically largest number.
32. You are given a file of text, where each line contains a number
(which may be either an integer or have decimal places). There will be
no extra characters other than the number or the newline at the end of
each line. Sort the lines in descending order - - such that the first line
holds the (numerically) largest number and the last line holds the
(numerically) smallest number.
33. You are given a file of text, which contains temperature
information about American cities, in TSV (tab-separated) format. The
first column is the name of the city and the next four columns are the
average temperature in the months of Jan, Feb, March and April (see
the sample input). Rearrange the rows of the table in descending order
of the values for the average temperature in January.
34. You are given a file of tab separated weather data (TSV). There is
no header column in this data file.
The first five columns of this data are: (a) the name of the city (b) the
average monthly temperature in Jan (in Fahreneit). (c) the average
monthly temperature in April (in Fahreneit). (d) the average monthly
temperature in July (in Fahreneit). (e) the average monthly
temperature in October (in Fahreneit).
You need to sort this file in ascending order of the second column (i.e.
the average monthly temperature in January).
35. You are given a file of pipe-delimited weather data (TSV). There
is no header column in this data file. The first five columns of this data
are: (a) the name of the city (b) the average monthly temperature in
Jan (in Fahreneit). (c) the average monthly temperature in April (in
Fahreneit). (d) the average monthly temperature in July (in Fahreneit).
(e) the average monthly temperature in October (in Fahreneit).
You need to sort this file in descending order of the second column (i.e.
the average monthly temperature in January).
36. In this challenge, we practice using the uniq command to
eliminate consecutive repetitions of a line when a text file is piped
through it.
Given a text file, remove the consecutive repetitions of any line.
37. In this challenge, we practice using the uniq command to
eliminate consecutive repetitions of a line when a text file is piped
through it.
Given a text file, count the number of times each line repeats itself.
Only consider consecutive repetitions. Display the space separated
count and line, respectively. There shouldn't be any leading or trailing
spaces. Please note that the uniq -c command by itself will generate
the output in a different format than the one expected here.
38. Given a text file, count the number of times each line repeats
itself (only consider consecutive repetions). Display the count and the
line, separated by a space. There shouldn't be leading or trailing
spaces. Please note that the uniq -c command by itself will generate
the output in a different format.
This time, compare consecutive lines in a case insensitive manner. So,
if a line X is followed by case variants, the output should count all of
them as the same (but display only the form X in the second column).
So, as you might observe in the case below: aa, AA and Aa are all
counted as instances of 'aa'.
39. Given a text file, display only those lines which are not followed
or preceded by identical replications.

You might also like