I have files with sections defined by the starting section composed oy TITLE
, SUBTITLE
, followed by comma separated KEYWORD
.
## TITLE [SUBTITLE] KEYWORD,KEYWORD
The ending is done using
## END OF TITLE [SUBTITLE]
I want to ensure that the file contains the corresponding closing part to the definition.
How can I make a test that check the file has things as should be. I need the test in bash.
## FAML [ASMB] keyword,keyword
Some text
Description
END OF FAML [ASMB]
Some Code
More text
FALUN [GONG] keyword,keyword
Some text
Description
END OF FALUN [GONG]
More Text
Have started with following to capture the actual strings for the corresponding section.
while read line; do
if [[ $line =~ ^##\ ([A-Z]+)\ \[([A-Z]+)\]\ (.*),(.*)$ ]]; then
title=${BASH_REMATCH[1]}
subtitle=${BASH_REMATCH[2]}
keywords=${BASH_REMATCH[3]}
keywords2=${BASH_REMATCH[4]}
echo "Title: $title"
echo "Subtitle: $subtitle"
echo "Keywords: $keywords, $keywords2"
fi
done < input.txt
Attempted to run the code on the following, but the printing is not keywords array printing is not happening.
## DN [AMBIT] bash,resource
## hodeuiihoedu
## AVAL:
## + ooeueocu
## END OF DN [AMBIT]