0

Looking to read a paragraph from the attached textfile.txt, set $fg_color, print the paragraph, then read another paragraph, set the next $fg_color, print the paragraph, etc... and then loop to the top of the file again until CTRL-C is pressed. Would also like a switch to set the print speed. I found the following but couldn't figure out how to read a paragraph then print it, and read the next paragraph in the same file.. etc.

for fg_color in {0..$(tput colors)}; do tput setaf $fg_color printf "Color $fg_color " done

textfile.txt contains the following:

Lorem ipsum dolor sit amet, id cum perpetua vulputate? An nec sumo regione! Id nostro ocurreret dignissim quo, vel in modo mutat sadipscing, ex vix voluptua adipiscing. Pro et viderer
copiosae, sit ne case rebum hendrerit? Repudiare gloriatur vituperata sea ex, eos ad adversarium liberavisse?

Mel alii periculis deterruisset ei, ut sea vero assum inciderint! Scripta omnesque in eos, an mundi clita per. Et pro quando menandri, nostrum interpretaris ad est? Quando semper oblique
ex vel, vel id dicant constituto!

Sit tamquam persius maiorum ut. Has solum qualisque ad? Duo justo nullam in? Est an graeci evertitur, no cum tractatos principes, fugit zril detraxit eum in?

Alia regione ex vis, summo accusamus sed te, dolore facilisi vel no? Cu vis decore tamquam? Mel ne aliquid fuisset! Id corrumpit cotidieque vel, justo regione est ei. Id graece equidem
reformidans ius, quo saperet phaedrum ut, nonumy verear albucius mel ut! No tibique probatus adolescens eam. Ne mea ignota equidem.

Et cum elit exerci singulis, cu velit cotidieque eos! Quo eu viris ubique gubergren, no has esse debet persecuti? Usu ei stet definitionem, vel ad ipsum mentitum! Malis sensibus perpetua
sed eu, vis ei legimus inermis? Sed ex verear ornatus gubergren, duo ei duis sapientem. Porro legimus efficiendi est in.

Lucilius adolescens his id, eu nec habemus oporteat! Tacimates inimicus contentiones ut mel, has omnis consul sententiae cu. Quo te veritus definitionem, veri mollis numquam vis in, te quo
mentitum electram iudicabit. Sea et quis mutat, in autem debet dicant per, voluptua recusabo philosophia nec ei?
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • `{anything...$variable}` doesn't work. See [BashPitfalls #33](http://mywiki.wooledge.org/BashPitfalls#for_i_in_.7B1...24n.7D); thus, that code you found was broken in the first place. – Charles Duffy Sep 02 '20 at 16:56
  • BTW, when you say a "paragraph" -- it looks like you want to read until the next blank line, is that correct? – Charles Duffy Sep 02 '20 at 16:58
  • BTW, it would be _easiest_ if your paragraphs, instead of being separated by blank lines, were separated by a sigil character like a NUL. Then all you need is `while IFS= read -r -d '' paragraph; do ...; done – Charles Duffy Sep 02 '20 at 17:00
  • Alternately, if you use the linked answer to read each paragraph into an array, you can do something like `for idx in "${!array[@]}"; do tput setaf "$idx"; printf '%s\n' "${array[$idx]}" ''; done` – Charles Duffy Sep 02 '20 at 17:02
  • Yes read until the next blank line. Willing to try your suggestion, but can't really find a way to replace or append blank lines with a NULL. – surfd4wg Sep 02 '20 at 18:41
  • The accepted answer to https://stackoverflow.com/questions/57673497/how-do-i-split-a-text-file-into-an-array-by-blank-lines shows how to do exactly that (replacing or appending blank lines with NULs). – Charles Duffy Sep 02 '20 at 18:45

0 Answers0