How to compare two files and extract some data with Python -


i have 2 files: file1, file2. file2 contains of file1 , many more. example:

file1: data1/111  data2/222  data3/333   file2: data1/111 \ewr\xcgf\wer 54645623456.xml data23/42234 \asdqw\aqerf 23525.xml data2/222 \asd\qwe 234234.xml data66/2331 \a53\fdf355 12312333311.xml data3/333 \from\where 123123.xml data4/444 \xcv\sdf\ghf 98546.xml  , many more... 

so, i'm trying print out lines exist on both files file2. means print out must have data in every line. path , xml file name.

i've tried;

lines1 = open(path1).readlines() lines2 = open(path2).readlines()  in lines1:     j in lines2:         if in j:             print(j.rstrip()) 

this prints lines @ lines2 i'm trying find out is; search first line lines1 in lines2 , if finds anywhere in lines2, print line lines2, , forth. after should same second line in lines1

can help?

thank time.

lines1 = open(path1).readlines() lines2 = open(path2).readlines()  l1 in lines1:     if l1 in lines2:         print(l1) 

or using list comprehension:

lines1 = open(path1).readlines() lines2 = open(path2).readlines() print([line line in lines1 if line in lines2]) 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -