Hi I have a md file containing the below string and I want to write a regular expression for this.
Conditions
- The id will be anything.
- The type will be youtube,vimeo etc
- ID and type are mandatory fields
{% include video.html id="T3q6QcCQZQg" type="youtube" %}
So I want to check the string is in a proper format in bash script otherwise will through an error.
Current code look like this . The below code is working for me without an ID. But I need to add a regex for id as well
IFS=$'\n' read -r -d '' -a VIDEOS < <( grep "video.html" "$ROOT_DIR$file" && printf '\0' )
#output => {% include video.html id="T3q6QcCQZQg" type="youtube" %}
for str in "${VIDEOS[@]}"
do
if [[ "$str" =~ ({%)[:space:][:space:][:space:][:space:]$ ]]; then
flag="dummy"
echo "Invalid format:: $second"
fi
done
Please help
/
" etc. Can you show a verbatim example (possibly anonymized) of the initialgrep
output? – AdminBee Jul 05 '21 at 13:14{% include video.html id="330853122" type="vimeo" %} `
– Meera Sebastian Jul 05 '21 at 13:23id="T3q6QcCQZQg
(no closing quote) be invalid? This file format isn't going to be easy to validate. Since it looks a little bit like XML, a basic XML parser might be the way to go. – Jeremy Boden Jul 05 '21 at 13:51awk
is certainly better suited for the task. If the latter, a shell script may indeed be your best approach. – AdminBee Jul 06 '21 at 15:24