<pre><code>l = ['TEC,FW,AS.blaram.111,311496,20181009042152033,20181009042152033,0,480,j8vg3046nhcs2p47ehci3ng6gpgal9hah9dqi1h9hhfaj100,3507b59a19602f0c96792e180d2469d1@20.116.21.9,Cisco-CUCM20.5,sip:+ACE8777447585984834,sip:+220037585984834,sip:+42086081330@man.blaram.com,sip:+8777447585984834@20.116.21.51:5060,sip:+221344903000@20.120.70.132:5060,sip:+221491668070@man.blaram.com,CUST56,C15_GR01,pstn,+221491668070,sip:+221491668070@man.blaram.com,CUST56,C15_GR01,mobile,447585984834000,+227585984834,onnet,1001501,1001501', 'TEC,FW,AS.blaram.111,311497,20181009042152355,20181009042152355,0,480,afc81a7e0aefe660dabb2963acf280,7ee0dd6bb34472945b18c959049f514f@20.116.21.9,NotPresent,sip:+ACE8777447585984834,sip:+220037585984834,sip:+222086081330@man.blaram.com,sip:+8777447585984834@man.blaram.com:5060,sip:+221344903000@20.116.21.13:5060,sip:+221491668070@man.blaram.com,CUST56,C15_GR01,pstn,+221491668070,sip:+221491668070@man.blaram.com,CUST56,C15_GR01,mobile,447585984834000,+227585984834,onnet,1001501,1001501', 'TEC,FW,AS.blaram.111,311498,20181009042152828,20181009042152828,0,480,afc81a7e0aefe660dabb2963acf280,5f29e2b4ef5a19c6a489aa53f01c000c@20.116.21.9,NotPresent,sip:+ACE8777447585984834,sip:+220037585984834,sip:+222086081330@man.blaram.com,sip:+8777447585984834@man.blaram.com:5060,sip:+221344903000@20.116.21.13:5060,sip:+221491668070@man.blaram.com,CUST56,C15_GR01,pstn,+221491668070,sip:+221491668070@man.blaram.com,CUST56,C15_GR01,mobile,447585984834000,+227585984834,onnet,1001501,1001501', 'TEC,IT,AS.blaram.111,311499,20181009042153373,20181009042202478,9105,normal,afc81a7e0aefe660dabb2963acf280,bc4213fa64c67cbdc8e80c5a437a7677@20.116.21.9,NotPresent,sip:+224441491668070,sip:+221491668070,sip:+222086081330@1.1.9.1,sip:+224441491668070@man.blaram.com:5060,sip:+221344903000@20.116.21.17:5080,CUST56,C15_GR01,pstn,+221491668070,sip:+221491668070@man.blaram.com,1001501', 'TEC,IT,AS.blaram.111,311500,20181009042358780,20181009042414784,16004,normal,8deba7200aefe860dabb2b5049eb70,279e60f3eb07aa44c55b8a4b804667bf@20.116.21.9,NotPresent,sip:+744441491603331,sip:+221491603331,sip:+222086081330@1.1.9.1,sip:+224441491603331@man.blaram.com:5060,sip:+221344903000@20.116.21.17:5080,CUSTOMER02,GROUP01 - CLUSTER1,pstn,+221491603331,sip:+221491603331@man.blaram.com,1000201']
# I remove this line: te = '\n'.join(l)
FILTER = ['sip:+220', 'sip:+494', 'sip:+119']
for row in l:
# for each row, you split by ','
r = row.split(',') # so, r = ['TEC', 'IT', ...]
# r[1] will always be 'IT' or 'FW'
if r[1] == 'IT':
# add your logic here
elif r[1] == 'FW':
# add your logic here
print('\n'.join(result))
</code></pre>
<blockquote>
<p><strong>Update</strong></p>
</blockquote>
<pre><code>import operator
from functools import reduce
l = ['TEC,FW,AS.example.111,311496,20180509042152033,20180509042152033,0,480,j8vg3046nhcs2p47ehci3ng6gpgal9hah9dqi1h9hhfaj100,3507b59a19602f0c96792e180d2469d1@10.105.86.9,Cisco-CUCM10.5,sip:+PLT8777447585984834,sip:+440093779379739,sip:+42086081330@example.com,sip:+8777447585984834@10.105.86.51:5060,sip:+441344903000@10.110.70.132:5060,sip:+441499737979@example.com,CUST,M79_PL01,pstn,+441499737979,sip:+441499737979@example.com,CUST,M79_PL01,mobile,447585984834000,+447585984834,onnet,1001501,1001501', 'TEC,FW,AS.example.111,311497,20180509042152355,20180509042152355,0,480,afc81a7e0aefe660dabb2963acf280,7ee0dd6bb34472945b18c959049f514f@10.105.86.9,NotPresent,sip:+PLT8777447585984834,sip:+440093779379739,sip:+442086081330@example.com,sip:+8777447585984834@example.com:5060,sip:+441344903000@10.105.86.13:5060,sip:+441499737979@example.com,CUST,M79_PL01,pstn,+441499737979,sip:+441499737979@example.com,CUST,M79_PL01,mobile,447585984834000,+447585984834,onnet,1001501,1001501', 'TEC,FW,AS.example.111,311498,20180509042152828,20180509042152828,0,480,afc81a7e0aefe660dabb2963acf280,5f29e2b4ef5a19c6a489aa53f01c000c@10.105.86.9,NotPresent,sip:+PLT8777447585984834,sip:+440093779379739,sip:+442086081330@example.com,sip:+8777447585984834@example.com:5060,sip:+441344903000@10.105.86.13:5060,sip:+441499737979@example.com,CUST,M79_PL01,pstn,+441499737979,sip:+441499737979@example.com,CUST,M79_PL01,mobile,447585984834000,+447585984834,onnet,1001501,1001501', 'TEC,IT,AS.example.111,311499,20180509042153373,20180509042202478,9105,normal,afc81a7e0aefe660dabb2963acf280,bc4213fa64c67cbdc8e80c5a437a7677@10.105.86.9,NotPresent,sip:+444441499737979,sip:+441499737979,sip:+442086081330@172.16.90.1,sip:+444441499737979@example.com:5060,sip:+441344903000@10.105.86.17:5080,CUST,M79_PL01,pstn,+441499737979,sip:+441499737979@example.com,1001501', 'TEC,IT,AS.example.111,311500,20180509042358780,20180509042414784,16004,normal,8deba7200aefe860dabb2b5049eb70,279e60f3eb07aa44c55b8a4b804667bf@10.105.86.9,NotPresent,sip:+744441498738722,sip:+441498738722,sip:+442086081330@172.16.90.1,sip:+444441498738722@example.com:5060,sip:+441344903000@10.105.86.17:5080,CUSTOMER02,GROUP01 - CLUSTER1,pstn,+441498738722,sip:+441498738722@example.com,1000201']
FILTER = ['sip:+420', 'sip:+34', 'sip:+44149']
result = []
for row in l:
r = row.split(',')
if r[1] == 'IT':
if (r[12][:8] in FILTER) or (r[12][:7] in FILTER) or (r[12][:10] in FILTER):
result.append(row)
if r[1] == 'FW':
if (r[13][:8] in FILTER) or (r[13][:7] in FILTER) or (r[13][:10] in FILTER):
result.append(row)
for row in result:
print(row)
print() # jump line between the output result
</code></pre>
<blockquote>
<p><strong>Output</strong></p>
</blockquote>
<pre><code>TEC,FW,AS.example.111,311496,20180509042152033,20180509042152033,0,480,j8vg3046nhcs2p47ehci3ng6gpgal9hah9dqi1h9hhfaj100,3507b59a19602f0c96792e180d2469d1@10.105.86.9,Cisco-CUCM10.5,sip:+PLT8777447585984834,sip:+440093779379739,sip:+42086081330@example.com,sip:+8777447585984834@10.105.86.51:5060,sip:+441344903000@10.110.70.132:5060,sip:+441499737979@example.com,CUST,M79_PL01,pstn,+441499737979,sip:+441499737979@example.com,CUST,M79_PL01,mobile,447585984834000,+447585984834,onnet,1001501,1001501
TEC,IT,AS.example.111,311499,20180509042153373,20180509042202478,9105,normal,afc81a7e0aefe660dabb2963acf280,bc4213fa64c67cbdc8e80c5a437a7677@10.105.86.9,NotPresent,sip:+444441499737979,sip:+441499737979,sip:+442086081330@172.16.90.1,sip:+444441499737979@example.com:5060,sip:+441344903000@10.105.86.17:5080,CUST,M79_PL01,pstn,+441499737979,sip:+441499737979@example.com,1001501
TEC,IT,AS.example.111,311500,20180509042358780,20180509042414784,16004,normal,8deba7200aefe860dabb2b5049eb70,279e60f3eb07aa44c55b8a4b804667bf@10.105.86.9,NotPresent,sip:+744441498738722,sip:+441498738722,sip:+442086081330@172.16.90.1,sip:+444441498738722@example.com:5060,sip:+441344903000@10.105.86.17:5080,CUSTOMER02,GROUP01 - CLUSTER1,pstn,+441498738722,sip:+441498738722@example.com,1000201
</code></pre>
<blockquote>
<p><strong>UPDATE: Explanations</strong></p>
</blockquote>
<p>当第2列是<code>IT</code>时,您对第13列感兴趣。所以<code>r[12]</code>给出了:<code>sip:+441498738722</code>。
当第2列是<code>FW</code>时,您对第14列感兴趣。所以,<code>r[13]</code>给出了:<code>sip:+442086081330@example.com</code>。你知道吗</p>
<p>您的筛选器是:<code>FILTER = ['sip:+420', 'sip:+34', 'sip:+44149']</code>。它包含3个项目。第一项的长度为<strong>8</strong>。
第二项的长度为<strong>7</strong>,最后一项的长度为<strong>10</strong>。你知道吗</p>
<p>所以要知道<code>r[12]</code>(<code>sip:+441498738722</code>)或<code>r[13]</code>(<code>sip:+442086081330@example.com</code>)元素是否在<code>FILTER</code>中,
如果其中一个(至少)在<code>FILTER</code>中,则必须获取前8、7和10个字符并测试<strong>。你知道吗</p>
<pre><code>if (r[12][:8] in FILTER) or (r[12][:7] in FILTER) or (r[12][:10] in FILTER):
# code
</code></pre>
<p><strong>例如:</strong><code>r[12]</code>是<code>sip:+441498738722</code>。所以前8个字符是<code>r[12][:8]</code>,也就是<code>sip:+441</code>。前7名
字符是<code>r[12][:7]</code>,也就是<code>sip:+44</code>。前10个字符是<code>r[12][:10]</code>,也就是<code>sip:+44149</code>。现在,你可以
请注意,对于这个<code>r[12]</code>(<code>sip:+441498738722</code>),只有<code>r[12][:10]</code>(<code>sip:+44149</code>)在<code>FILTER</code>变量中。所以,你可以
将此<code>row</code>添加到<code>result</code>列表。你知道吗</p>
<p>这是相同的逻辑,当<code>row</code>的第二列是<code>FW</code>。你知道吗</p>