Help with reading and assigning variables

Hi Gurus,

I have a file named log with 2 lines
Each line is a file name. eg

$ cat log
monday
tuesday

I need to read log and assign each output(filename) to a different variable.
The following doesn't work:-

while read A B
do
echo " a is ${A} "
echo " b is ${B} "
done < log

Here's the output:-

a is monday
b is
a is tuesday
b is

What I want is to have the following :-

a is monday
b is tuesday

Any ideas?? I'm using ksh.

Thank you in advance.

Try this,

paste -s day.log | while read A B; do echo " a is ${A} "; echo " b is ${B} "; done
1 Like
xargs <log | while read A B
do
echo " a is ${A} "
echo " b is ${B} "
done

Thank you Pravin27

It works like magic!:b:

ctsgnb

This code doesn't work. It just hangs, with no output. I had to ctrl C out of it. I'm using Pravin27's example, it would be nice to know how the xargs works it out though.

Oooops typo error, i forgot the redirection, code fixed, see my previous post (modif added in red)

---------- Post updated at 06:06 PM ---------- Previous update was at 05:16 PM ----------

xargs <log | while read A B
do
echo " a is ${A} "
echo " b is ${B} "
done
1 Like

Hi ctsgnb

Great, it works now.... thanks!:b: I now have two ways to run my script.