Sort Command #3 HackerRank Solution

Hello coders, In this post, you will learn how to solve Sort Command #3 HackerRank Solution. This problem is a part of the Linux Shell series.

Sort Command #3 HackerRank Solution
Sort Command #3 HackerRank Solution

Sort Command #3 HackerRank Solution

Problem

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.

Input Format

A text file where each line contains a positive number (less than 100) as described above.

Output Format

Output the text file with the lines reordered in numerically ascending order.

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

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

Sort Command #3 HackerRank Solution

#Output the text file with the lines reordered in numerically ascending order.
sort -n

Note: This problem (Sort Command #3)  is generated by HackerRank but the solution is provided by  chase2learn. This tutorial is only for Learning and Educational purpose. Sort Command #3 HackerRank Solution

Leave a Comment