Question: This is how i made my CSV file:

```
with open('Mail_Txt.csv', 'w', encoding='utf-8', newline='') as csvfile:
    fieldnames= ['Sender', 'Subject', 'Snippet']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames , delimiter=',')
    for val in final_list:
        writer.writerow(val)

```

I try many methods to print the Sender column of the CSV file. But I fail all the time. so, help me to print the first or `'Sender'` column of the CSV file

Answer: 
I have stored device configuration in device\_config.cfg file. using ciscoconfparse and regex module I am able to do this.

```
from ciscoconfparse import CiscoConfParse
import re

final_list = []
cisco_file = 'device_config.cfg'

cisco_cfg = CiscoConfParse(cisco_file)
parent_child_line = cisco_cfg.find_objects_w_child(parentspec=r"", childspec=r"10.10.10.10")
parsed_data = cisco_cfg.find_objects(r"10.10.10.10")

# print(parent_child_line)
# print(parsed_data)

for p_line in parent_child_line:
    # print(p_line.text)
    final_list.append(p_line.text)
    for child in p_line.children:
        if re.search(r'10.10.10.10', child.text):
            # print(child.text)
            final_list.append(child.text)

print('\n#############################################\n')

for i in parsed_data:
    if not re.search(r'^\s\w', i.text):
        # print(i.text)
        final_list.append(i.text)
        print(final_list)

```
I suggest re-grouping `data_list` strings into separate, individual lists and then check for a match and grab the results once the conditions are met.

See [this Python demo](https://ideone.com/rp5ILd):

```py
import re
data = """ip access-list extended test1
 deny   tcp any eq tacacs any
 permit ip any any
ip access-list extended test2
 permit ip any any
 permit ip host 10.10.10.1 any log
 permit icmp host 10.10.10.2 any
 permit tcp any any eq 22
 permit tcp any any eq tacacs
 permit tcp any any
 permit udp any any
ip access-list extended test3
 permit udp any any eq 123 log
 permit udp any any eq 1234 log
 permit ip any any"""

data_list = data.splitlines()
data_ll = []
search_key = '10.10.10.1'
tmp = []
for line in data_list:
    if line and not line[0].isspace():
        if tmp:
            m = re.search(fr".*\b{re.escape(search_key)}\b.*", "\n".join(tmp))
            if m:
                data_ll.append([tmp[0], m.group()])
            tmp = [line.rstrip()]
        else:
            tmp.append(line.rstrip())
    elif line and line[0].isspace():
        tmp.append(line.rstrip())

print(data_ll)

```

Output:

```
[['ip access-list extended test2', ' permit ip host 10.10.10.1 any log']]

```

I also initialize the regex from the `search_key` variable and that is why I use the `re.escape(search_key)` to escape the `.` chars, else, they match any chars other than line feeds.