A Bash solution
#!/bin/bash
while IFS= read -r line1; do
while IFS= read -r line2; do
printf "C: %s %s\n" "$line2" "${line1/#F: }"
done < file2
done < file1
This loops over file1, and for each line of file1 loops over file2. The printf line assembles the output, and the parameter expansion for line removes the leading F: .
Result:
C: server1 24000 user1 password1
C: server2 24000 user1 password1
C: server3 24000 user1 password1
C: server4 24000 user1 password1
C: server1 24000 user2 password2
C: server2 24000 user2 password2
C: server3 24000 user2 password2
C: server4 24000 user2 password2
C: server1 24000 user3 password3
C: server2 24000 user3 password3
C: server3 24000 user3 password3
C: server4 24000 user3 password3
A solution with join and sed
This would work as well:
join -j 50 -o 2.1,1.1 -t '~' file1 file2 | sed s'/~F:/ /;s/^/C: /'
This is a slight abuse of join. -j 50 says to join on matching field number 50, which doesn't exist and is thus considered equal for all lines, resulting in the Cartesian product of the two files:
$ join -j 50 file1 file2
F: user1 password1 server1 24000
F: user1 password1 server2 24000
F: user1 password1 server3 24000
F: user1 password1 server4 24000
F: user2 password2 server1 24000
F: user2 password2 server2 24000
F: user2 password2 server3 24000
F: user2 password2 server4 24000
F: user3 password3 server1 24000
F: user3 password3 server2 24000
F: user3 password3 server3 24000
F: user3 password3 server4 24000
To get the lines into proper order, we specifiy the output format with -o 2.1,1,1. Because the default field delimiter is whitespace, we specify a character that is not contained in the input as the new delimiter with -t '~':
$ join -j 50 -o 2.1,1.1 -t '~' file1 file2
server1 24000~F: user1 password1
server2 24000~F: user1 password1
server3 24000~F: user1 password1
server4 24000~F: user1 password1
server1 24000~F: user2 password2
server2 24000~F: user2 password2
server3 24000~F: user2 password2
server4 24000~F: user2 password2
server1 24000~F: user3 password3
server2 24000~F: user3 password3
server3 24000~F: user3 password3
server4 24000~F: user3 password3
And finally, we replace ~F: with a space on each line and prepend C: using sed:
$ join -j 50 -o 2.1,1.1 -t '~' file1 file2 | sed 's/~F:/ /;s/^/C: /'
C: server1 24000 user1 password1
C: server2 24000 user1 password1
C: server3 24000 user1 password1
C: server4 24000 user1 password1
C: server1 24000 user2 password2
C: server2 24000 user2 password2
C: server3 24000 user2 password2
C: server4 24000 user2 password2
C: server1 24000 user3 password3
C: server2 24000 user3 password3
C: server3 24000 user3 password3
C: server4 24000 user3 password3
If the order of the lines doesn't matter, this can be slightly shortened to
$ join -j 50 file2 file1 | sed 's/F://;s/^/C:/'
C: server1 24000 user1 password1
C: server1 24000 user2 password2
C: server1 24000 user3 password3
C: server2 24000 user1 password1
C: server2 24000 user2 password2
C: server2 24000 user3 password3
C: server3 24000 user1 password1
C: server3 24000 user2 password2
C: server3 24000 user3 password3
C: server4 24000 user1 password1
C: server4 24000 user2 password2
C: server4 24000 user3 password3
batch-filetag, as it is not applicable to your question. It refers to batch-files in the specific context of MS-DOS, Windows, or OS-2 operating systems. Please don't use tags just because they contain similar sounding names or phrases. Tags here have specific meanings. If you're not sure, read the description of the tag. If you're still not sure, don't use it; if it's necessary, someone will add it for you.Pythontag