as shown in the figure above, there is a multi-line string returned by the linux command. You need to cut the first "CLA", of each line under the INCLUDE column and count the total number of" CLA" "returned under the INCLUDE column of all rows (only the first one for each line). My code is as follows:
import re
ss = "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP+ n | ID | NAME | DESCRIPTION | INCLUDE | ROLLBACK | nPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP+ n | 1481439 | CSS Upgrade Patch | Upgrade CSS to R9A for case | CLA-sharp1481439 | | True | n | 1501340 | Artifact CLA-sharp1501340 ZBX Ansi | support ZBX Ansible Module Ex | CLA-sharp1501340v6.1.5 CLA-sharp1499108v6.1.0 | True | n | 1527137 | Artifact CLA-sharp1527137v6.1.2 PR | support CMCC PRMTOOL Feature | CLA-sharp1527137v6.1.2 | | | True |.
for line in ss.split ("n") [3:]:
info = line[1:-1].split("|")
a=re.search(r"(.*?)CLA", info[3])
b = a.group()
print b
c = b.count("CLA")
print c
the results are as follows:
CLA
1
my question is: the three CLA strings in the table have been regularly matched, but only three 1s have been counted. How to achieve the return value with a total of 3 through code? Thank you.