i am having single file called bar.txt which is having list of files as follows,

bar.txt -

1.txt

2.txt

3.txt

each file inside bar.txt having some similar contents.

1.txt -

spec = sadasdsad

2.txt -

spec = dddddd

3.txt -

spec = ppppppppp

how can i open all files inside bar.txt and extract the data from all file and store in other file called foo.txt ?

in foo.txt i want extracted data mentioned below,

foo.txt -

spec = sadasdsad

spec = dddddd

spec = ppppppppp

```
 outfile = open('bar.txt', "rw")
 outfile_1 = open('foo.txt', "w")
     for f in outfile:
        f=f.rstrip()
        lines = open(f,'rw')
        lines = re.findall(".*SPEC.*\\n",lines)
        outfile_1.write(lines)
 outfile.close()

```