Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerRank Sort Command #6 problem solution

YASH PAL, 31 July 20246 February 2026

In this HackerRank Sort Command #6 problem solution, 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).

Input Format

A text file with multiple lines of tab separated data. The first five fields have been explained above

Output Format

Sort the data in ascending order of the average monthly temperature in January.

Introduction

In linux, the most vanilla version of ‘sort’ simply rearranges the lines in a file, in lexicographical order. Using a variety of flags and options, sort can also be extended in various powerful ways. The command can also be used for sorting tables of data, delimited by commas (csv) or tabs (tsv) or even spaces; on a particular column or field. The -k option helps sort the input file on a particular field, i.e. the column number.

HackerRank Sort Command #6 problem solution

Problem solution.

sort -t$'t' -k 2 -n

Second solution.

sort -g -t$'t' -k 2

Third solution.

sort -t $'t' -n -k2,2

Fourth solution.

cat | sort -n -k2 -t $'t'

coding problems solutions Hackerrank Problems Solutions linux shell HackerRankLinux shell

Post navigation

Previous post
Next post

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes