syntax - How to escape quotation marks when initializing a unix/shell command in python? -


i using target.write command write line

line4 = "do echo "$i|$( geoiplookup -f /usr/share/geoip/geoip.dat $i | cut -d' ' -f4 -n | sed -e 's/,$//' -e '/^$/d' )" >> $output;".format(name) 

but face error :

  file "m.py", line 8     target.write('output=/var/www/html/result/{0}/rips.txt;\necho > $output;\nfor in $( cat /var/www/html/result/{0}/pwips.txt );\ndo echo "$i|$( geoiplookup -f /usr/share/geoip/geoip.dat $i | cut -d' ' -f4 -n | sed -e 's/,$//' -e '/^$/d' )" >> $output;;\ndone'.format(name))                                                                                                                                                                                                                               ^ syntaxerror: invalid syntax 

also removed code

| sed -e 's/,$//' -e '/^$/d' 

but got the file without ' strings after -d ?

any ?

thanks

don't forget r, creates raw string literal. work unless there """ within string. in case, use r'''...''' instead.

import os os.system(r"""do echo "$i|$( geoiplookup -f /usr/share/geoip/geoip.dat $i | cut -d' ' -f4 -n | sed -e 's/,$//' -e '/^$/d' )" >> $output;""".format(name)) 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -