0

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' {} \;
> 
> 
> 
don_crissti
  • 82,805
grepit
  • 213
  • (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 01: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 Answers1

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
  • 81,074