I am printing a multiline string mstr
with colour codes defined in array tseq[knam]
, with knam
being a colour identifier (e.g. Blu:, Grn:, etc).
For instance, with the multiline string mstr
,
mstr= "\n \
Grn: \n \
Some green text \n \
More green text \ n \
Blu: \n \
Moving to blue text \n \
With more blue text here"
to produce the text appropriately coloured
Some green text
More green text
Moving to blue text
With more blue text here
The following code identifies the colour and sets the appropriate colour code to cpt
. But has the problem that the line that contains the colour declaration (e.g. Grn:
, Blu:
) in also printed.
Thus I want to skip the value of astr[i]
when knam == str
. How can I solve this ?
## Split with newline character, and store into array
nlines = split(mstr, astr, "\n")
str = astr[i] ; gsub(/[[:blank:]]+/, "", str)
for (i = 1; i <= nlines; i++) {
## Capture KNAM from TSEQ[KNAM] and match with string ASTR[I]
for ( knam in tseq ) {
if ( knam == str ) { cpt = tseq[knam] }
}
print cpt astr[i] rst
}
I have introduced continue
, and test knam == str
again.
for (i = 1; i <= nlines; i++) {
## Capture KNAM from TSEQ[KNAM] and match with string ASTR[I]
for ( knam in tseq ) {
if ( knam == str ) { cpt = tseq[knam] ; continue }
}
if ( knam == str ) { print "" } else { print cpt astr[i] rst }
}