Saturday, 15 September 2012

full text search - Find and replace multiple strings in file then output to new filename python -


I am creating a dragon script that can read a source file and generate another file with a string for the name .

For example,

is the source file in the MacDress.Cnf.xml

Let me replace '6000' to '6001' in many places of the MacDrade.com. I need the .xml, so I want to output to newmacaddress.cnf.xl.

I have it

  #! Write open = file = f (file) for file in / usr / bin / python #read and f: if line canteen ('66001'): newline = line.replace ('66001', '60001')  

To add it I can do CSV or whatever else and to do more to run the script.

60002 >> macaddressfromcsv.cnf.xml 60003 >> MacDesFreshCSSVCNF.xml 60004 etc.

Sorry, I am very new to this that any help would be great.

It is not clear from your question what all your goals are, but I address some of them Will try to If you want to take input from a file, then modify it, and then type any other file you can:

  buffer = ""; In open ("input_file") with: buffer = in.read (); # Modify ... open (out of "output_file", 'W') out. Written (buffer);  

Note: You will need to use <__ future__ import with_statement with in Python version 2.5.

You can actually use the function to make multiple replacements:

  buffer = re.sub ('6000', '6001', buffer)  

For additional information on using CSV, please see a more detailed explanation or an example of what you are trying to achieve.


No comments:

Post a Comment