------------------------------------------------------------ Playing with text, (circumlunar), 07/11/2018 ------------------------------------------------------------ 1. In the beginning, there | 7. Several tools presented was a curious fellow named | themselves as worthwhile Tfurrows. | options, and most of these | he did try to use, but only 2. He wondered how hard it | a few of them ened up being would be to create a gopher | what Tfurrows wanted. post that was formatted | like many common english | 8. Finally, he settled on Bibles, with the text | fold, head, tail, and pr, broken up into two columns. | in that order. | 3. There was no good reason | 9. Fold was used to take for his curiosity- as is | his text file- which was generally the case with | simply long lines of text curiosity- but he wanted to | with numbers at the see how it would be done | beginning of each one- and nonetheless. | break them down to the size | he wanted (28 characters, 4. Ideally, he would use a | so that two columns would few common command-line | be about 60 characters.) tools, indigenous to any | good *nix system. | 10. Head and tail served | their simple purpose well, 5. Surely the task could be | breaking the input file accomplished cleanly using | into two parts without a programming language, but | breaking any words. Tfurrows wasn't in the mood | to program, he was in the | 11. And finally, pr was mood to cobble together a | perfectly suited to merging hasty and useless script. | the two new text files into | a single, 2-column ouput 6. So, away he went on his | with a nicer divider in the adventure, starting with a | middle. text file to test with and | a bash script that would | 12. Tfurrows saw that the take a filename as an input | output was what he wanted, argument. | and he ended his foolish | quest for the evening. And of course, here's the script. It's nothing special, I was just bored and had some time to waste. I don't see this as useful, but nonetheless, I'd love to see cooler ways to do the same thing: //// START SCRIPT //// #!/bin/bash if [ $# -eq 0 ] then echo "Please provide a filename." exit 1 fi temp_file=$(mktemp) temp_file2=$(mktemp) fold -s -w 28 $1 > $temp_file linecount=`wc -l < $temp_file` firsthalf=$(($linecount/2)) secondhalf=$(($linecount-$firsthalf)) head -n $firsthalf $temp_file > OUTa tail -n $secondhalf $temp_file > OUTb pr -S" | " -w 60 -t -m OUTa OUTb > $temp_file2 cat $temp_file2 rm $temp_file rm $temp_file2 rm OUTa rm OUTb //// END SCRIPT //// As far as the input text file, it was just lines of text starting with numbers, one "verse" per line, with a blank line between. I'm pleased with the output.