Hello All,
I have a following task that I need to accomplish through a script or program and I am looking for some help as I have exhausted my ideas.
1. given: a text file with thousands of lines
2. find: pattern A in file and get line number ( grep -n works)
3. find: the first occurence of pattern B up from line number obtained in step2
4. find: pattern A again but after the line number previously found
5. find: the first occurence of pattern B up from the new line number in step4
6. repeat the process until the file is completely processed.
Possible solutions?
a) will vi work programmatically with forward search '/', go to line 'nG' and reverse searching '?' ?
b) I think C program will work with file pointer, seek and other facilities. But I have no C compiler.
c) will java work - RandomAccessFile - seek?
d) how about awk? not sure if it has reverse searching capability.
e) how about a combination of grep -n file, head -n, tac |grep
this may be a possibility but could be tedious with a few intermediary files
Please let me know if you have any suggestions on how I could go about this.
Thanks.