Sort Output in Shell

Level 239 keystrokes

Sorts data.csv numerically by its second column and shows the first 10 lines.

Shell code

# -t',' splits lines at commas; -k2 sorts on the key starting at field 2
# -n compares that field as a number (so 5 < 12); head prints the first 10 lines
1sort -t',' -k2 -n data.csv | head -n 10

Output

user1,5,active
user2,12,active
user3,18,inactive
user4,25,active
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Shell code and how often they appear.

  • -× 4
  • '× 2
  • ,× 1
  • .× 1
  • |× 1

More Shell examples at level 2

← Shell typing practice