bash: read file one line at a time
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
Here is the easiest solution.
In this example, we print the lines one at a time and append line numbers:
file='my_file.txt'
i=0;
while read -r line; do
let i=$i+1
printf "$i\t%s\n" "$line"
done < $file