sort

Reads a file and sorts it in descending or ascending order.

NAME
     sort -- sort or merge records (lines) of text and binary files

SYNOPSIS
     sort [-bcCdfghiRMmnrsuVz] [-k field1[,field2]] [-S memsize] [-T dir]
          [-t char] [-o output] [file ...]]
     sort --help
     sort --version

github

  • The file in jupyter notebook format on github is here.

google colaboratory

Environment

The author’s OS is macOS, and the options are different from those of Linux and Unix commands.

When you actually run the command, the leading ! and %%bash in the first line.

!sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G95
!bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.

Example usage

%%bash
echo -e "b\nc\na\nz\ny" > temp1.txt
cat temp1.txt
sort -r temp1.txt > temp2.txt
echo -e "\nsorted"
cat temp2.txt
b
c
a
z
y

sorted
z
y
c
b
a