Merging contents of two files

Katharina.Pergens at dlr.de Katharina.Pergens at dlr.de
Wed May 15 16:41:52 EDT 2002


I want to write a script for searching the name of the author of the
source files and generating an output file containing the author name
(containing in java source file; see below), Explanation, File and Line
(containing in txt file; see below).

Bjorn Pettersen schrieb:
> 
> > From: Katharina.Pergens at dlr.de [mailto:Katharina.Pergens at dlr.de]
> >
> > Sorry sending a html file. Once again.
> > So what I have is a text file (.txt) like the following:
> >
> > Abbreviation  Explanation             File                    Line
> > ------------  -----------             ----                    ----
> >       xyz     comment for class       /home/de/abc.java       13
> >       ...             ...                     ...             ...
> >
> > The txt file contains of several lines and rows. The rows are
> > seperated by tabs. The source file (mentioned as row 'File'
> > in txt file) are java files. I search for
> > firstname.secondname in the header:
> >       * Created: dd/mm/yyyy firstname.secondname
> >
> > How to write the script. Thanks for your help!!
> 
> Are you asking for help in reading the text file or finding the specific
> line in the java file?
> 
> To get the filenames you can do something like:
> 
>   def getFilenames(txtfile):
>       res = []
>       for line in file(txtfile):
>           res.append( line.split('\t')[2] )
>       return res
> 
> (you'll probably have to add some error checking <wink>).
> 
> For finding the specific line in the .java file, something like the
> following should work:
> 
>   for fileName in getFilenames(txtfile):
>       fp = file(filename)
>       while 1:
>           line = fp.readline()
>           if not line: break
>           if line.find('firstname.secondname') != -1:
>               # you found the line...
>               break # unless you want to find multiple occurences
> 
> hth,
> -- bjorn



More information about the Python-list mailing list