Skip to main content
1 of 2
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Since using shell loops for text processing is considered bad practice, I would recommend a different approach that uses dedicated text-processing tools. In particular, awk comes to mind:

awk '{printf "text %s text\n",$0}' textfile.txt 

This will use Awk's builtin printf function (using the same formatting syntax as the well-known C function) to print the entire current line (represented by $0) enclosed by text on both ends.

As for why your approach didn't work, it can be that if the text file was edited on a Windows-based machine, the line endings are in a format the Linux doesn't correctly interpret. In that case, run the file through dos2unix, as in

dos2unix textfile.txt
AdminBee
  • 23.6k
  • 25
  • 55
  • 77