python code to create a merged file
<p>I want to create a a file from two input files. Input1 is a single line file which contains 18 words separated by space. Input2 is multiple lines file which holds different size strings separated by space. The Output shall contains the presence (1) and absence (0) the 18 words in the Input2. Here is how it shall look like.</p>

<h2>Input1</h2>

<pre><code>word1 Word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12 word13 word14 word15 word16 word17 word18 
</code></pre>

<h2>Input2</h2>

<pre><code>word1 Word2 word3 word4 

word6 word7 word8 word9 word15 word16 word17

word1 word5 word7 word8 word11 word16 word18

word1 word18

word1 Word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12 word13 word14 word15 word16 word17 word18

word5

word8 word12 word15
</code></pre>

<h2>Output</h2>

<pre><code>word1 Word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12 word13 word14 word15 word16 word17 word18

1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 0

1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 1 0 1

1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 

0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0
</code></pre>

<p>Assuming you can read the data from file and hold it into two string say input1 and input2 below code should do what you are looking for</p>

<pre><code>word_list_1 = input1.split(" ")
for str in input2.split("\n"):
    word_list_2 = str.split(" ")
    for  word in word_list_1:
        if word in word_list_2:
            sys.stdout.write("1")
        else:
            sys.stdout.write("0")
        sys.stdout.write("")
    sys.stdout.write("\n")
</code></pre>

python