1

This shell :

for i in $(cat file1.txt) and j in $(cat File2.txt)       
do
    echo " portname=$i domainid=$j "       
done

NOT getting proper output .

Can you suggest to how to use it

Indent
  • 4,675
  • 1
  • 19
  • 35
arun kumar
  • 23
  • 4
  • 1
    What was the input, current output and what did you expect? See also [mcve]. – rene Oct 25 '17 at 14:51
  • Input File1 :port1 PORT2 FILE2 1 2 Output: portname=PORT1 domainid= portname=PORT2 domainid= portname=and domainid= portname=j domainid= portname=in domainid= portname=1 domainid= portname=2 domainid= – arun kumar Oct 25 '17 at 14:56
  • 1
    There is an [edit] link that allows you to update your question. Don't add useful info in the comments. – rene Oct 25 '17 at 15:02
  • Using `for` loop with 2 `in` you obtain a cartesian product – Indent Oct 25 '17 at 15:13

2 Answers2

2

Using file descriptor redirection :

while read -r i && read -r j <&3
do
    echo " portname=$i domainid=$j ";
done < file1.txt 3<File2.txt
Indent
  • 4,675
  • 1
  • 19
  • 35
  • Could you explain what the `3` stand for at the first and last line ? – Will Oct 25 '17 at 15:26
  • `3` is a custom file descriptor (`0` is stdin `1`is stdout `2`is stderr ) https://stackoverflow.com/questions/5256599/what-are-file-descriptors-explained-in-simple-terms – Indent Oct 25 '17 at 15:52
2

Using paste command :

paste file1.txt File2.txt |
while read -r i j
do
    echo " portname=$i domainid=$j "
done
Indent
  • 4,675
  • 1
  • 19
  • 35