pattern matching - Finding two strings in a file within n lines of each other -


How do I want to find two strings in a text file within each other of the lines, for example, the file was given :

ABC DF - ssssss
ssssss
ssssss
ssssss
ssssss
pqr xyz

I "myscript abc pqr 5" Do not want to return "myscript abc pqr 7 (or more)" to return the file name that was found and return (bonus) mailing lines and intermediate people. It should work with any string .

Just to make it interesting, I am working on Solaris 10 and I do not have access to any gnu commands or extensions. This is like swimming.

TIA < / P>

Nigel.

This script gets you in almost any way: / P>

  #! / Bin / bash if [[$ (pcregrep -M "$ 1. * (\ n ..) * $ 2" test .txt | wc -l] == $ 3 ]] Then you can resonate "echo" and resonate "not found" file   

Instead of printing, you can modify the file name to find "found".

This script was inspired by.

Comments

Popular posts from this blog

How can I add a seperate action listener to all 14 of my buttons at once that can determine player turn?(java) -

php - Sorting an multidimension array using usort fails -

Simple file compression in C -