Skip to main content
1 of 3
grepit
  • 213
  • 2
  • 6

complicated command replace in files using sed

Need your help, I have looked all over the stackexchange and spent hours over this simple replacement string problem but I've had no luck. I simply 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' {} \;
> 
> 
> 

I have exhausted my search options on stackoverflow/StackExchange and web and I need your help to solve this problem.

(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
  • 213
  • 2
  • 6