I am creating some documentation that includes a list of packages that are to be installed for a Debian Server.
This is a single line and I would like to sort the list of packages alphabetically.
Using a small example of the packages, the best I could come up with was as follows:
I create a file with the line in it.
echo "aspell-en lynx unzip bzip2 p7zip bzip2 gzip rar unrar tar zip unzip bash-completion" > /tmp/unsortedline.txt
I then use this command to try and sort the line.
tsort /tmp/unsortedline.txt |sort -d |awk '{ str1=str1 $0 " "}END{ print str1 }'
However if you use my example above which has an odd number of items seperated by spaces you get this error
tsort: /tmp/unsortedline.txt: input contains an odd number of tokens
So I end up just putting another character in the file so there is an even amount and it then works and outputs the line alphabetically. I then remove the added character afterward.
Can anyone provide a more elegant way to do this?
Also, whilst on the subject if anyone has an idea on how I could insert " \" at the end of each line defined by a set amount of characters (72 for example) at the same time it would also be useful, e.g.
aspell-en bash-completion bzip2 \
gzip lynx p7zip rar tar unrar \
unzip zip