Hi

Running a test on a linux box, with python.

Trying to do a search/replace over a file, for a given string, and
replacing the string with a chunk of text that has multiple lines.

>From the cmdline, using sed, no prob. however, implementing sed, runs
into issues, that result in a "termination error"

The error gets thrown, due to the "\" of the newline. SO, and other
sites have plenty to say about this, but haven't run across any soln.

The test file contains 6K lines, but, the process requires doing lots
of search/replace operations, so I'm interested in testing this method
to see how "fast" the overall process is.

The following psuedo code is what I've used to test. The key point
being changing the "\n" portion to try to resolved the termination
error.


import subprocess


ll_="ffdfdfdfghhhh"
ll2_="12112121212121212"
hash="aaaaa"

data_=ll_+"\n"+ll2_+"\n"+qq22_
print data_

cc='sed -i "s/'+hash+'/'+data_+'/g" '+dname
print cc

proc=subprocess.Popen(cc, shell=True,stdout=subprocess.PIPE)
res=proc.communicate()[0].strip()



===================
error
sed: -e expression #1, char 38: unterminated `s' command
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to