#!/bin/bash #Takes the $1 argument of the beginning line number, and the # $2 argument of the element you are looking for # $3 is the name of the file LineNumberDownFunction () { echo "arguments are $1 $2 and $3" local BeginLineNumber #BeginLineNumber="" BeginLineNumber="$1" local EndSectionElement #EndSectionElement="" EndSectionElement="$2" local File #File="" File="$3" local FoundEndSectionElement FoundEndSectionElement="" local EndLineNum #EndLineNum="" local LineNum local EndSectionLineNumber #TestSectionInformation="" echo "file is $File" LineNum="$BeginLineNumber"; echo "BeginLineNumber is $BeginLineNumber" #read #initialize EndLineNum which will ultimately be the line with the ending component tag, "$EndSectionElement" EndLineNum="$(($LineNum+1))"; echo "EndLineNum is $EndLineNum" #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 head -"$EndLineNum" "$File" | tail -1| grep -q "$EndSectionElement" > /dev/null FoundEndSectionElement="$?" #FoundEndSectionElement="$(head -"$EndLineNum" "$File" | tail -1| grep -q "$EndSectionElement";echo "$?")" #FoundEndSectionElement="$(sed -n "$EndLineNum"p "$File" | grep -q "$EndSectionElement";echo "$?")" echo "FoundEndSectionElement is $FoundEndSectionElement" #read while [ "$FoundEndSectionElement" = "1" ]; do EndLineNum="$(($EndLineNum+1))" echo "EndLineNum is $EndLineNum" # echo "$(head -"$EndLineNum" "$File" | tail -1)" head -"$EndLineNum" "$File" | tail -1 | grep -q "$EndSectionElement" FoundEndSectionElement="$?" #FoundEndSectionElement="$(head -"$EndLineNum" "$File" | tail -1 | grep -q "$EndSectionElement";echo "$?")" echo "FoundEndSectionElement is $FoundEndSectionElement and the EndSectionElement is $EndSectionElement and current line being tested is $EndLineNum" done echo "Beginning line Number of the Section is $BeginLineNumber" EndSectionLineNumber="$EndLineNum" echo "Ending Line Number of the Section is $EndSectionLineNumber" TestSectionInformation=$(echo "$BeginLineNumber:$EndSectionLineNumber:$EndSectionElement:$File") echo "end LineNumberDownFunction" }