there is a large text файл1 . eg:
a b c d e There is another text файл2 with several lines. eg:
b c d How to use posix -utilit (or at least gnu -utilit, and in the extreme case - to the maximum platform-specific si ) to find the line number in the first file, starting with which these files match? for the given example, it will be 2 (starting from the second line in the first file contains exactly the same lines as in the second).
at the moment I found only a way to find out if the second file is included in the first one
$ grep -qzP "$(sed ':a;N;$!ba;s/\n/\\n/g' файл2)" файл1 && echo входит but it does not allow to know the line number from which the match began.
an explanation about the program for sed : it replaces each newline in файле2 with two \n characters (backslash and n ) to make a regular expression for grep . borrowed from here: How can I replace a newline (\ n) using sed? .