How can I skip printing on the line that matches pattern. For remaining lines display with the corresponding printf until a new line matches another pattern.
Want I want is the Wht:, Grn:, and Blu: codes to indicate the colour of subsequent text. So they're not to be output but instead used for changing the colour setting.
Here's what I have so far, which handles colouring but but doesn't do what I want:
theone ()
{
printf '%s\n' "$@" \
| while IFS="" read -r vl; do
if [[ "$vl" =~ ^[[:space:]]*Wht:[[:space:]]*$ ]]; then
printf '%s%s%s\n' "${wht}" "$vl" "${rst}"
elif [[ "$vl" =~ ^[[:space:]]*Grn:[[:space:]]*$ ]]; then
printf '%s%s%s\n' "${grn}" "$vl" "${rst}"
elif [[ "$vl" =~ ^[[:space:]]*Blu:[[:space:]]*$ ]]; then
printf '%s%s%s\n' "${blu}" "$vl" "${rst}"
else
printf '%s%s%s\n' "${wht}" "$vl" "${rst}"
fi
done
}
Here is an example
var="
Grn:
Some lines in green
More green lites
Green light again
Blu:
Now turning to blue
And more blue"
theone "$var"
The result would be
Some lines in green
More green lites
Green light again
Now turning to blue
And more blue