Merging contents of two files

Bjorn Pettersen BPettersen at NAREX.com
Wed May 15 16:05:05 EDT 2002


> 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