Skip to main content
better explanation
Source Link
seshoumara
  • 3.7k
  • 1
  • 13
  • 30

Bash + coreutils, 44 bytes

sed '/^the /I!s,^,@ ,'|sort -dk2|sed s,@\ ,,

I sort the bands fromExplanation: the 2nd space separated field onward, creating a temporary 1st field '@ ' for bands that don't start with 'the ', case insensitive. The input and output format is one band per line.

sed '/^the /I!s,^,@ ,'   # prepend '@ ' to each line not starting with 'the ', case
                         #insensitive. This adds a temporary field needed by sort.
sort -dk2                # sort in ascending dictionary order by 2nd field onward
sed s,@\ ,,              # remove the temporary field

Test run (using a here-document with EOF as the end marker):

./sort_bands.sh << EOF
> Queen
> Aerosmith
> Sunny Day Real Estate
> The Strokes
> EOF

Output:

Aerosmith
Queen
The Strokes
Sunny Day Real Estate

Bash + coreutils, 44 bytes

sed '/^the /I!s,^,@ ,'|sort -dk2|sed s,@\ ,,

I sort the bands from the 2nd space separated field onward, creating a temporary 1st field '@ ' for bands that don't start with 'the ', case insensitive. The input and output format is one band per line.

Test run (using a here-document with EOF as the end marker):

./sort_bands.sh << EOF
> Queen
> Aerosmith
> Sunny Day Real Estate
> The Strokes
> EOF

Output:

Aerosmith
Queen
The Strokes
Sunny Day Real Estate

Bash + coreutils, 44 bytes

sed '/^the /I!s,^,@ ,'|sort -dk2|sed s,@\ ,,

Explanation: the input and output format is one band per line

sed '/^the /I!s,^,@ ,'   # prepend '@ ' to each line not starting with 'the ', case
                         #insensitive. This adds a temporary field needed by sort.
sort -dk2                # sort in ascending dictionary order by 2nd field onward
sed s,@\ ,,              # remove the temporary field

Test run (using a here-document with EOF as the end marker):

./sort_bands.sh << EOF
> Queen
> Aerosmith
> Sunny Day Real Estate
> The Strokes
> EOF

Output:

Aerosmith
Queen
The Strokes
Sunny Day Real Estate
Source Link
seshoumara
  • 3.7k
  • 1
  • 13
  • 30

Bash + coreutils, 44 bytes

sed '/^the /I!s,^,@ ,'|sort -dk2|sed s,@\ ,,

I sort the bands from the 2nd space separated field onward, creating a temporary 1st field '@ ' for bands that don't start with 'the ', case insensitive. The input and output format is one band per line.

Test run (using a here-document with EOF as the end marker):

./sort_bands.sh << EOF
> Queen
> Aerosmith
> Sunny Day Real Estate
> The Strokes
> EOF

Output:

Aerosmith
Queen
The Strokes
Sunny Day Real Estate