...and just after saying we wouldn't do his homework for him.
But in any case the above is really incorrect (as is the thread title), because we
Don't Read Lines With For! File processing should always be done with a
while+read loop.
Also here's a hint for you. When you need to work on every nth something-or-other, you should generally make use of the
modulo operator (
%). It outputs the remainder after a division operation. Example:
Code:
if (( a % 2 == 0 )); then
echo "the number is even" #e.g. 8/2 has a remainder of zero
else
echo "the number is odd" #e.g. 9/2 has a remainder of one
fi
Now just put a counter in your loop to test. Save the line on every odd count, and concatenate the next line to it on every even count and print it.
(Actually, what
I would probably do is simply read all the lines into an array with the
mapfile command (assuming bash), then use
printf to print them back out two at a time. Saves a lot of headache.)