Read line by line and write in another file shell script
<p>I have a file called "test_file1". I want to read each line of this file and write it to another file called "test_file2". Both of these files are in the same directory.</p>

<p>I tried </p>

<pre><code>#!/bin/sh
# My first Script
echo "Hello World!"
file=$(&lt;test_file1.txt)
echo "Test" &gt;&gt; test_file2.txt 
while IFS= read -r line;do
    echo -e "legendary" &gt;&gt; test_file2.txt
    echo "$line" &gt;&gt; test_file2.txt
done &lt;"$file"
echo "completed"
</code></pre>

<p>The script writes "Test" into test_file2.txt but does not write 'legendary' or the lines in test_file1 into test_file2.</p>

<p>Can someone please help.</p>

<p>Thank you.</p>