Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank Sort Command #7 problem solution

YASH PAL, 31 July 2024

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

Input Format

A text file with multiple lines of pipe-delimited data. The first five fields have been explained above

Output Format

Sort the data in descending 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, sorting 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. The -t option helps specify the delimiting character depending on the file format.

For example, we’d use:

-t $’t’ for a tab-delimited file    

-t’,’ for a comma delimited file    

-t’|’ for a pipe delimited file

HackerRank Sort Command #7 problem solution

Problem solution.

sort -n -r -t'|' -k2

Second solution.

sort -t'|' -k 2 -n -r

Third solution.

sort -t '|' -k2 -nr

Fourth solution.

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

coding problems solutions linux shell

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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