I have a text file I need to verify, and I am trying to figure out how to check that an expected value exists.
An example of my file is
InitialPattern:
Value1=somevalue
Value2=somevalue
Value3=somevalue
InstallationName=InstallationX
I don't care about lines 2-4, but I need to verify that in line 5
InstallationName=Installation1
To throw a wrench in it, this line does not always exist, at which point the pattern starts again with
InitialPattern:
What I have so far kind of works, but not in the case that the line does not occur altogether:
instName="Installation1"
installationNames=$(cat file.txt | grep InstallationName)
IFS=$'\n' read -rd '' -a array <<< "$installationNames"
for element in "${array[@]}"
do
if [[ "$element" =~ "$instName" ]]; then
test="pass"
else
test="fail"
break
fi
done
any ideas? I was looking at this post: Print Matching line and nth line from the matched line Where the user got the forth line after an pattern occurrence - I was thinking if I could store this value I could compare it to the expected value, but I am not entirely sure how to store it yet.
Any guidance is welcome!