So I have testfile which contains
Line one
Another line
and this is the third line
My script reads this file, does some stuff and I end up with a variable that should contain it. Kind of doing
filevar=$(cat testfile)
(the important thing here is that I cannot access the file directly).
I’ll be using the contents of that variable to generate an HTML code and one things I have to do is to add <br> to the end of each line. The problem is, there doesnt seem to any EOLs in my var:
echo $filevar
Line one Another line and this is the third line
How do I read the file properly to keep the EOLs? Once I have that I can simply sed s/$/<br>/g, but till then…
thanks!
Instead of doing
echo $filevardoecho "$filevar"(note the double quotes). This will send a single argument to echo and then you can pipe this to sed.With sed, this will be treated as 3 lines, so you do not need the g option. This works with me (bash and cygwin):