0

Let's say I have the following variable:

var='a foo\nb bar\nc something'

Now I wan't to for example replace lines that contain 'bar' with '1 bar'. But keep in mind, that I want to keep my line feed signs, so I can save the output in a variable again. The result should look like:

$ echo $var2
a foo\n1 bar\nc something

I have tried to do it with Sed but the line feeds get replaced with spaces when I'm storing the output of Sed in a variable.

Mihael
  • 13
  • 5
  • 1
    Make sure when you're checking the variable with echo that you put quotes around it. `echo "$var2"` will print with the new-lines, but `echo $var2` will not. – jas May 26 '18 at 14:16
  • @jas That solved it, thanks. I feel dumb now. – Mihael May 26 '18 at 14:23

0 Answers0