Need to read a file line by line in a shell script (bash/sh)? Here's a piece of code that will help you:
file="/home/myusername/file.txt"
while read line
do
...
# Do something here with the line variable
...
done < $file
Here, put the name of the file to be read into the file variable, and the script will execute everything written inside the do...done block for each line of the file, with the line itself stored in the line variable.
Comments