I have a file from which I need to find 10 characters before and after every substring instance.
For example, from:
(1M characters)...ldkS9jfasdfalkasjFalskdfjsDljBASHcslakfjsalZkf4djfsa3Jkjl...(1M characters)
I would like the output:
lskdfjsDljBASHcslakfjsal
Of course, in the file there are many instances of the string, and I would like to return all of them in the same manner of having the previous and subsequent 10 characters.
Right now I am using grep
as follows:
grep -o -P '.{0,10}BASH.{0,10}' input.txt > output.txt
While this works, it seems to be very slow. Is there any way to speed up the process? Thanks in advance.