problem handling lov in FOR loop

Hi all,

i am trying to process a list of values in FILE like this:

aaa:bbb
ccc:ddd
eee:fff

With the following logic:

for INFO in FILE
do
export F1=`cut -f1,3,5,7 -d":" < FILE`
export F2=`cut -f2,3,5,7 -d":" < FILE`
 
ssh $F1 bash <<EOF
 
echo $F1
echo $F2
date
EOF
done

The problem I am finding is that the cut is extracting ALL values in the first column of FILE and the script is erroring because the second row value is not being handled.

Is there anyway I can have the script process ie cut the first row in turn, do the ssh and then do the second row and third in turn?

Hope this is clear,

Thanks in advance for any help.

jd

Are trying to read the values separated by colon (:slight_smile: into two different variables ? If so, you can use while loop to iterate throught the file and read the columns into variables using awk command:

var1=awk -F":" '{print $1)'  $inputLine
var2=awk -F":" '{print $2)'  $inputLine

Explain in Details with output you want..

so I have a file with values:
aaa:bbb
ccc:ddd
eee:fff

And the logic is thus:

for each row in turn,

ssh to host with first value of first row
echo second value of first row
exit
ssh to host with first value of second row
echo second value of second row
exit
ssh to host with first value of third row
echo second value of third row
exit

Something like this:

oldIFS="$IFS"
IFS=':'
while read field1 field2
do
 echo $field1
 echo $field2
 #### something with the 2 fields ###
done < inputfile
IFS="$oldIFS"

you are excepting this one...

awk -F ':' '{ print $1>"test1.txt"} {print $2>"test2.txt"}' test.txt

getting confused..

This is what i suggested:

while read line 
do
 column1=`echo $line|awk -F":" '{print $1}'`
 column2=`echo $line|awk -F":" '{print $2}'`
 echo "column1 = $column1"
 echo "column2 = $column2"
 
## After you get the values in two diff variables, use them to do whatever you want.

done < file.txt

here is what I have so far.

 
FILE=/tmp/listsid.ls
exec 3<&0
exec 0<$FILE
while read line
do
     F1=awk -F":" '{print $1)'
     F2=awk -F":" '{print $2)'
     ssh $F1 bash <<EOF
     echo $F2
     EOF
done
/

There are problems with the basic syntaxes you have used. See my last post.

Thanks for all the help.
i solved the problem with the following syntax.

FILE=/tmp/listsid.ls
while read line
do
F1=`echo $line|awk -F":" '{print $1}'`
F2=`echo $line|awk -F":" '{print $2}'`
ssh -q $F1 bash <<EOF >> /tmp/mailos.out
echo
echo " "
echo $F1 ":" $F2
echo