Simple bash for loop problem

I'm just trying to make a script that runs in command line to echo each line in a text file. Everything i found on google is telling me to do it like this but when I run it it just echos removethese.txt and thats it. Anyone know what im doing wrong?

for i in removethese.txt; do echo $i; done

but if I do this

for i in 1 2 3; do echo $i; done

it works...

essentially i need it to run a command for me and not just echo but I was testing it with an echo first and I can't get that to even run.... *sigh*

Try this:

while read aLine
do
printf "\n $aLine"
done < removethese.txt

sweet, thanks!

the reason this did not work:

for i in removethese.txt; do echo $i; done

is because the for loop does not know what to do with the removethese.txt file. it does not accept files as an input. you can add cat command or similar commands that will read or extract contents of the file then feed them to the for loop. in this case using cat command:

for i in `cat removethese.txt`; do echo $i; done

thanks

n=`wc -l $1 | awk '{print $1}'`
for ((i=1;i<=$n;i++))
do
        echo `head -$i $1 | tail -1`
done

this will also work....preferably, dont use the above code for very huge files(>10mb) :stuck_out_tongue:
or else u can peacefully use the scripts mentioned earlier :slight_smile: