Sort Command #4 HackerRank Solution

Hello Programmers, In this post, you will know how to solve the Sort Command #4 HackerRank Solution. This problem is a part of the HackerRank Linux Shell Series.

Ezoicreport this adSort Command #4 HackerRank Solution
Sort Command #4 HackerRank Solutions

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

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.

Input Format

A text file where each line contains a number as described above.

Output Format

The text file, with lines re-ordered in descending order (numerically).

Sample Input

9.1
43.7
2.2
62.1
2.1
9.3
43.5
4.6
44.6
4.7
42.7
47.4
46.6
4.5
55.6
4
9.2
66.6
2
2.3

Sample Output

66.6
62.1
55.6
47.4
46.6
44.6
43.7
43.5
42.7
9.3
9.2
9.1
4.7
4.6
4.5
4
2.3
2.2
2.1
2

Sort Command #4 HackerRank Solution

#The text file, with lines re-ordered in descending order (numerically).
sort -n -r

Note: This problem (Sort Ccommand #4) is generated by HackerRank but the Solution is Provided by  BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: Sort Command #5 HackerRank Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad