Content of variable

I have a variable that contains filenames like this:

variable="file_1.extension<blank>file_2.extension<blank>file_3.extension<blank>file_4.extension and so on"

How can I make filenames to be separated by newline: (I tried Sed but it didn't worked well)

file_1.extension
file_2.extension
file_3.extension
file_4.extension

I don't want another temporary file and want to do this with the variable:

while read filename; do

some stuff

done<< END
$variable
END

Thank you for suggestions!

echo $variable | tr " " "\012"

or

for f in $variable; do echo $f; done

# cat file1.txt
file_1.extension file_2.extension file_3.extension file_4.extension


# sed 's/ /\n/g' file1.txt
file_1.extension
file_2.extension
file_3.extension
file_4.extension



thanks, works like a charm :slight_smile:

I had the very same sed.. so there has to be another problem :frowning:

echo $variable | tr ' ' '\n'

Why not simplify the problem and just use a while loop instead of a here-document i.e.

variable="file1 file2 file3"

for filename in $variable
do
   .......
done