0

This question already has an answer here:

I want to replace the below strings

replace: print 'Status Code: {code}'.format(code=r.status_code)

with: print('Status Code: {code}'.format(code=r.status_code))

Here is the command I ran which fails

find ./ -type f -exec  gsed 's/'print 'Status Code: {code}'.format(code=r.status_code)'/'print('Status Code: {code}'.format(code=r.status_code))'/g' {} \;

I tried to use \ to avoid the special characters effect but still fails too and just hangs.

find ./ -type f -exec  gsed -i 's/print \'Status Code: {code}\'.format\(code=r.status_code\)/print\(\'Status Code: {code}\'.format\(code=r.status_code\)\)/g' {} \;
> 
> 
> 

marked as duplicate by don_crissti, Thomas, RalfFriedl, roaima, elbarna Nov 11 '18 at 21:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • (Please do NOT close and mark this as duplicate by simply referencing a generic sed or perl question, I've spent more than a few hours trying to research this on stackExchange and web without any hopes ) – grepit Nov 11 '18 at 1:45
  • 1
    That doesn't make it less of a duplicate... This has been asked so many times it's even boring. – don_crissti Nov 11 '18 at 13:00
1

You can either use double quotes around the expression, or close and re-open the single quotes around each literal ', like '\'':

sed "s/print 'Status Code: {code}'.format(code=r.status_code)/print('Status Code: {code}'.format(code=r.status_code))/"


sed 's/print '\''Status Code: {code}'\''.format(code=r.status_code)/print('\''Status Code: {code}'\''.format(code=r.status_code))/'
  • @steeldriver....you are simply awesome thank you – grepit Nov 11 '18 at 2:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.