0

Assuming I have a file called "students" containing this:

NEWTON Isaac
MAXWELL James
EDISON Thomas
TESLA Nikola

how I am supposed to sort these names with a bash script in shell ? Do I need to use a delimiter with carriage return ? Will this support accentuated characters ?

Thanks for your time.

imrems
  • 47
  • 3

1 Answers1

0

You can make use of the sort function.

$ cat stud.txt
NEWTON Isaac
MAXWELL James
EDISON Thomas
TESLA Nikola
$ sort stud.txt
EDISON Thomas
MAXWELL James
NEWTON Isaac
TESLA Nikola

To sort on last name, use the -k option.

$ sort -k 2 stud.txt
NEWTON Isaac
MAXWELL James
TESLA Nikola
EDISON Thomas
Bayou
  • 3,293
  • 1
  • 9
  • 22