Skip to content
Advertisement

sorting rows of a data file with Linux

I would like to sort the lines of a data file (each line idependent from each other) from the first character. For example, if I have a data file

JavaScript

I would like to end with something like

JavaScript

I have tried to do it using the sort command, but it sorts the columns (not the line). Transposing the data file +sort could be also a good solution (I don’t know any easy way for transposing datafiles).

Thanks for the help!

Advertisement

Answer

Perl to the rescue!

JavaScript
  • -n reads the input line by line
  • -a splits the line on whitespace into the @F array
  • -l adds newlines to print

See sort, join .

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement