wisdom
March 16, 2011, 11:09am
1
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
ctsgnb
March 16, 2011, 11:35am
3
xargs <log | while read A B
do
echo " a is ${A} "
echo " b is ${B} "
done
wisdom
March 16, 2011, 11:46am
5
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.
ctsgnb
March 16, 2011, 1:06pm
6
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
wisdom
March 17, 2011, 6:11am
7
Hi ctsgnb
Great, it works now.... thanks! I now have two ways to run my script.