Bash | Importing a .txt to .txt file, line by line with 'While Read'

740 Views Asked by At

I know this question appears rather frequently, but I cannot seem to find a solution on importing a .txt file line by line to another .txt with the While Read command:

line="input.txt"

while read -r line; do
  printf '%s\n' "$line"
done < outputfile.txt

I tried different alternatives, tried them all as variables, using the variables with their directories, tried cat on the input file, use of echo and printf but to no avail. Thanks in advance for any and all advance!

1

There are 1 best solutions below

2
On

I think you are just trying to combine files ?

cat input.txt >> outputfile.txt 

Not suggesting this but as an FYI :

file="input.txt"
while IFS= read -r line ;do
    echo "${line}" >> outputfile.txt 
done < "${file}"