get data from files combine them to a file

hi people;

this is my file1.txt:

192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
...

this is my file2.txt:

portnames
usernames
maxusercap
...

i want to write to file3.txt:

l ./getports 192.168.1.1 'get all;l+;get . portnames;l-'
l ./getports 192.168.1.1 'get all;l+;get . usernames;l-'
l ./getports 192.168.1.1 'get all;l+;get . maxusercap;l-'
... (goes up to parameters in file2.txt)
l ./getports 192.168.1.2 'get all;l+;get . portnames;l-'
l ./getports 192.168.1.2 'get all;l+;get . usernames;l-'
l ./getports 192.168.1.2 'get all;l+;get . maxusercap;l-'
... (goes up to parameters in file2.txt)
l ./getports 192.168.1.3 'get all;l+;get . portnames;l-'
l ./getports 192.168.1.3 'get all;l+;get . usernames;l-'
l ./getports 192.168.1.3 'get all;l+;get . maxusercap;l-'
... (goes up to parameters in file2.txt)

... (goes up to ip list in file1.txt)

ip addresses should be get from file1.txt, parameter names should be get from file2.txt and it must be put into file3.txt as shown.

while read file1line
do
   while read file2line
    do
      echo "l ./getports ${file1line} 'get all;l+;get . ${file2line};l-'" >> file3
    done < file2
done < file1
1 Like
awk -v q="'" 'FNR==NR{f2[$1];next}{for(i in f2) print "l ./getports " $1 " " q "get all;l+;get . " i ";l-" q}' file2.txt file1.txt > file3.txt
1 Like
 
TEST>while read line
> do
> for line1 in `cat file2`
> do
> echo "l ./getports $line 'get all;l+;get . $line1;l-'" >> op.txt
> done
> done < file1
1 Like

thanks for all your replies. all of the solutions work well :slight_smile: