View Full Version : I have two and need to get data from that using loop
aliahsan81
April 7th, 2009, 09:53 PM
Hi all i have two contain some data
like file1
123
345
345
File2
abc
xyz
I want to pass each value from both file to a command in a loop.I try cat with loop but not working because i have two file.And need to pass data from two file one by one to command.I am using bash
like command is this
ls $file1 $file2
can any one guid me
weresheep
April 7th, 2009, 10:59 PM
Hello,
I'm not sure if I understand what exactly you are asking for but try this...
paste file1 file2
and see
man paste
for more information.
-weresheep
aliahsan81
April 7th, 2009, 11:06 PM
Hi thanks for your quick answer but i know about paste
look my little example
file1
abc
bcd
yhx
file2
45
67
78
for in file1 file2
file1=get first value from file1
file2=get first value from file2
and soo on ...................
ls $file1 $file2
done
got my point
weresheep
April 7th, 2009, 11:25 PM
Okay,
How about...
paste file1 file2 | while read LINE ; do
f1=$(echo $LINE | awk '{print $1}')
f2=$(echo $LINE | awk '{print $2}')
echo "f1 is $f1 and f2 is $f2"
# Do stuff with $f1 and $f2 here
done
-weresheep
aliahsan81
April 7th, 2009, 11:40 PM
yes thanks
ghostdog74
April 8th, 2009, 01:06 AM
Okay,
How about...
paste file1 file2 | while read LINE ; do
f1=$(echo $LINE | awk '{print $1}')
f2=$(echo $LINE | awk '{print $2}')
echo "f1 is $f1 and f2 is $f2"
# Do stuff with $f1 and $f2 here
done
-weresheep
no need awk..
# paste file1 file2 | while read a b
> do
> echo $a $b
> done
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.