We are introduced to the
sort function here. Can we use
sort for sorting input not separated by newlines?
Though the function
sort only works to sort input separated by newlines, just as we have been able to chain together simple command line functions to accomplish complex tasks, we can do the same to sort input not separated by newlines. In order to do this, we will need to replace the symbols separating the input we would like to sort by newlines. To accomplish this, we can use the
sed command (which we also learn about in this section). For instance, if our input,
in.txt, is separated by spaces instead of newlines, we can sort the file by
sed -e "s/ /\n/g" in.txt | sort