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 #1 problem solution

YASH PAL, 31 July 2024

In this HackerRank Sort Command #1 problem solution, The sort command is frequently used for sorting input in text or TSV formats in various different ways. These ways may be either lexicographical, case insensitive, based on the numeric field only, based on a particular column, etc.

Sort Options

  1. The vanilla sort command simply sorts the lines of the input file in lexicographical order.
  2. The -n option sorts the file on the basis of the numeric fields available if the first word or column in the file is a number.
  3. The -r option reverses the sorting order to either the reverse of the usual lexicographical ordering or descending order while sorting in numerical mode.
  4. The -k option is useful while sorting a table of data (tsv, csv etc.) based on a specified column (or columns).
  5. The -t option is used while specifying a delimiter in a particular file where columns are separated by tabs, spaces, pipes etc.

In this challenge, we practice using the sort command to sort input in text or TSV formats. we have given a text file, order the lines in lexicographical order.

HackerRank Sort Command #1 problem solution

Problem solution.

sort

Second solution.

IFS=$'n' read -d '' -r -a lines
printf '%sn' "${lines[@]}" | sort

Third solution.

echo "$(</dev/stdin)" > file1234
sort file1234

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