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
Wht:
(maybe surrounded by whitespace on either side) and if found prints it in what I assume is white text. Similarly green text forGrn:
and blue forBlu:
, with a fallback of white text for any other line. So what do you actually want instead of this? Please clarify this in your question - not here as a comment. An example might help (show input data and - as best you can - corresponding output) – Chris Davies Feb 16 '23 at 23:01Wht:
,Grn:
, andBlu:
to indicate the colour of subsequent text. So they're not to be output but instead used for changing the colour setting – Chris Davies Feb 16 '23 at 23:04continue
andbreak
, but they would not continue to the next line. – Vera Feb 17 '23 at 09:03