I want to search for a specific string across multiple lines in a file and get the line in which the match was found.
However, my problem is, that the file contains one very long string, and not, i.e. words, and I want to search for a sub-sequence of this long string. Hence, I can not use pcregrep and just search for word1\nword2. Because I actually want to get the line number in which the match was found, I can not just remove all newline characters...
This is an example how my file looks like, I just capitalized the matching string so you could find it:
String to search:
File to search in:
abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde abcdeabcde***GCBCDBFCEEBCFHFCHAACCDGFCEGFFGEDFFAEAEDC BAEDHACEBEEEBCECHBCBFEECCBDHCBFG***ggfbhbgcedabceedfa fbaaechaabdbffbebecebaacfcfcdcggfchddcefbcbdegbbba
Does someone of you have an easy solution for this?
If there is no tool at hand to do it, I would just write a short python script to do it, but I guess any bash tool would be more efficient than that ...
Thank you very much for your answers, they work very well, if the position of the newline character is known.
However, I am sorry for being imprecise in my question. My problem is, that I do not know if there is a newline, or even more than one newline, within the string in the file and moreover, I do not know where it is. I corrected my search string by deleting the newline I had unwittingly inserted.
Is there some way to allow for a newline in any position of the string?