| 1 | #!/bin/bash | 
|---|
| 2 | #Takes the $1 argument of the beginning line number, and the | 
|---|
| 3 | # $2 argument of the element you are looking for | 
|---|
| 4 | # $3 is the name of the file | 
|---|
| 5 | LineNumberDownFunction () | 
|---|
| 6 | { | 
|---|
| 7 | echo "arguments are $1 $2 and $3" | 
|---|
| 8 |  | 
|---|
| 9 | local BeginLineNumber | 
|---|
| 10 | #BeginLineNumber="" | 
|---|
| 11 | BeginLineNumber="$1" | 
|---|
| 12 |  | 
|---|
| 13 | local EndSectionElement | 
|---|
| 14 | #EndSectionElement="" | 
|---|
| 15 | EndSectionElement="$2" | 
|---|
| 16 |  | 
|---|
| 17 | local File | 
|---|
| 18 | #File="" | 
|---|
| 19 | File="$3" | 
|---|
| 20 |  | 
|---|
| 21 | local FoundEndSectionElement | 
|---|
| 22 | FoundEndSectionElement="" | 
|---|
| 23 |  | 
|---|
| 24 | local EndLineNum | 
|---|
| 25 | #EndLineNum="" | 
|---|
| 26 | local LineNum | 
|---|
| 27 |  | 
|---|
| 28 | local EndSectionLineNumber | 
|---|
| 29 | #TestSectionInformation="" | 
|---|
| 30 | echo "file is $File" | 
|---|
| 31 | LineNum="$BeginLineNumber"; echo "BeginLineNumber is $BeginLineNumber" | 
|---|
| 32 | #read | 
|---|
| 33 | #initialize EndLineNum which will ultimately be the line with the ending component tag, "$EndSectionElement" | 
|---|
| 34 | EndLineNum="$(($LineNum+1))"; echo "EndLineNum is $EndLineNum" | 
|---|
| 35 | #This is to check the line and if it does not contain $EndSectionElement, add 1 to EndLineNum and go to the next line and check that one | 
|---|
| 36 | head -"$EndLineNum" "$File" | tail -1| grep -q "$EndSectionElement" > /dev/null | 
|---|
| 37 | FoundEndSectionElement="$?" | 
|---|
| 38 | #FoundEndSectionElement="$(head -"$EndLineNum" "$File" | tail -1| grep -q "$EndSectionElement";echo "$?")" | 
|---|
| 39 | #FoundEndSectionElement="$(sed -n "$EndLineNum"p "$File" | grep -q "$EndSectionElement";echo "$?")" | 
|---|
| 40 | echo "FoundEndSectionElement is $FoundEndSectionElement" | 
|---|
| 41 | #read | 
|---|
| 42 | while [ "$FoundEndSectionElement" = "1" ]; | 
|---|
| 43 | do | 
|---|
| 44 | EndLineNum="$(($EndLineNum+1))" | 
|---|
| 45 | echo "EndLineNum is $EndLineNum" | 
|---|
| 46 | # echo "$(head -"$EndLineNum" "$File" | tail -1)" | 
|---|
| 47 | head -"$EndLineNum" "$File" | tail -1 | grep -q "$EndSectionElement" | 
|---|
| 48 | FoundEndSectionElement="$?" | 
|---|
| 49 | #FoundEndSectionElement="$(head -"$EndLineNum" "$File" | tail -1 | grep -q "$EndSectionElement";echo "$?")" | 
|---|
| 50 | echo "FoundEndSectionElement is $FoundEndSectionElement and the EndSectionElement is $EndSectionElement and current line being tested is $EndLineNum" | 
|---|
| 51 | done | 
|---|
| 52 | echo "Beginning line Number of the Section is $BeginLineNumber" | 
|---|
| 53 | EndSectionLineNumber="$EndLineNum" | 
|---|
| 54 | echo "Ending Line Number of the Section is $EndSectionLineNumber" | 
|---|
| 55 |  | 
|---|
| 56 | TestSectionInformation=$(echo "$BeginLineNumber:$EndSectionLineNumber:$EndSectionElement:$File") | 
|---|
| 57 | echo "end LineNumberDownFunction" | 
|---|
| 58 |  | 
|---|
| 59 | } | 
|---|