Skip to main content
3 of 3
edited tags
don_crissti
  • 85.7k
  • 31
  • 234
  • 262

complicated command replace in files using sed

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' {} \;
> 
> 
> 
grepit
  • 213
  • 2
  • 6