Issue
Given a text file with multiple lines, I would like to iterate over each line in a Bash script. I had attempted to use cut
, but cut
does not accept \n
(newline) as a delimiter.
This is an example of the file I am working with:
one
two
three
four
Does anyone know how I can loop through each line of this text file in Bash?
Solution
Use cat
for concatenating or displaying. No need for it here.
file="/path/to/file"
while read line; do
echo "${line}"
done < "${file}"
Answered By - Benoit