Hello Everyone,
I just started scripting this week. I have no background in programming or scripting.
I'm working on a script to grep for a variable in a log file
Heres what the log file looks like. The x's are all random clutter
xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx ACTNUMBER=1234xxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxx FINISH:
I declared ACTNUMBER as a variable $ACTNUMBER
Basically the user will open a file and grep for the ACTNUMBER.
I've gotten as far as getting the file open with exec.
What I want the script to do is to grep for the ACTNUMBER and only print the line (with echo) if the line contains a START and the ACTNUMBER. I also want the script to echo all the data in the lines after until it reaches the word FINISH
I'm looking for the results in a numbered format output to display, with a carriage return between the results.
There's a twist though. Sometimes theres a nested START and FINISH within a START and FINISH and I need to have the script look for that as well. So it it finds two STARTS then find two ENDS. So if it finds one START, look for another START, if it finds another START look for two FINISH's.
I know grep only does one line at a time,
so if i do a grep -n START | grep -n ACTNUMBER=$ACTNUMBER
it will output lines with both the START and ACTNUMBER, and I need to get it to print all the lines after until it finds the line that read FINISH.
So what I need it to do is look for a START and ACTNUMBER. If it finds it then echo that particular line. Then search next line, even if it doesnt find it, to print that line, and the next, and if it reaches a FINISH, print the line, then start loop over.
I have a feeling some counters might be involved here but I'm really not sure how to implement this.
Thanks so much for any input and ideas on this.