This will read strange to anyone using bash. a while loop will go over every line
Code:
for ((eachline="${totallines}"; eachline>=1; eachline--))
You prepend the line count (as expected)
The next line you put out will have this value. Since you put out multiple lines after one iteration of this, this gives you your undesired behavior
Code:
do echo -n "${eachline}: "
You iterate through every line in the whole file, echoing out the line. Probably not what you want
Code:
for line in "$(cat myfile.txt)"
do echo "${line}"
Quote:
Based on your code example, if I were not wanting to just display (printf) contents of inputfile.txt but do some kind of processing on what is within inputfile.txt... Say as example I wanted to do something like dig a list of hostnames provided from inputfile.txt or do some simplistic housekeeping based off of what's in inputfile.txt? Is it likely to still be a while loop for that leg of a processing.
|
GazL gave you a good answer for this but to simplify it slightly,
Code:
count=$( wc -l < inputfile.txt )
while read line
do
other_processing_commands
dig +short "$line"
echo "$count": "$line"
(( count-- ))
done < inputfile.txt
28: Line
27: Line
26: Line
25: Line
24: Line
...