I am now having two text files with some of the lines beginning with the same pattern. For example,
1Mo 1,1 I love you. 1Mo 1,2 I like you. Hi 23,3 I am hungry. Hi 23,4 I am foolish.
1Mo 1,1 Ich liebe dich. 1Mo 1,2 Ich mag dich. Hi 23,5 Ich habe Durst. Hi 23,6 Ich bin neu.
File A and File B have two lines starting with the same pattern "1Mo 1,1" and "1Mo 1,2", respectively. My expected output is like this:
1Mo 1,1 I love you. 1Mo 1,2 I like you. 1Mo 1,1 Ich liebe dich. 1Mo 1,2 Ich mag dich.
My idea is that I should use grep to extract the beginning pattern of each line in file A then using these patterns to match each line in file B. I tried to write a grep command as follows, but it failed:
grep "^[.A-z]*\s[.]*\s" file A > extract.txt
This is the command I searched the community and adapted to use for the string matching in file B:
while read string; do grep "$string" file B; done < extract.txt
Is anybody having some idea about how to do the grep thing for pattern extraction and matching?