simple for loop/cat issue

ok..
so problem is:

I have a file that reads:
cat 123

1 and 2
3 and 4
5 and 6

I was using for loops to run through this information.

Code:

for i in `cat 123`
do
echo $i
done

shouldn't the output come as

1 and 2
3 and 4
5 and 6 ...(1)

rather, its coming as :

1
and
2
3
and
4

..... something like this...using ksh here...

lemme know what the issue is..I want to display output as (1)...no code alternatives pls..just was wondering what was wrong in this code..

thanks..!

#!/bin/ksh

while read i
do
   echo "${i}"
done < 123

---------- Post updated at 06:08 PM ---------- Previous update was at 06:07 PM ----------

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

no. this is because its using the default characters for $IFS(internal field separator) which is white space. set IFS='\n' prior to your loop and you should get what you expect. I would wrap your variable in double quotes though.

thanks frank...worked just fine..!

vgersh99 --- will remember the tags next time..