1

我想使用sed命令注释掉以下代码行。

实际代码:

response = HttpResponse()
response['Content-Disposition'] = 'attachment; filename=%s.zip' % file_name.replace('.shp','')
response['Content-length'] = str(len(zip_stream))
response['Content-Type'] = mimetype
response.write(zip_stream)
return response

我想要什么:

#response = HttpResponse()
#response['Content-Disposition'] = 'attachment; filename=%s.zip' % file_name.replace('.shp','')
#response['Content-length'] = str(len(zip_stream))
#response['Content-Type'] = mimetype
#response.write(zip_stream)
#return response

唯一的问题是文件很大,而且response到处都有,所以搜索应该根据上面提供的更具体。

给定的代码块位于特定文件的整个源代码的中间。

4

2 回答 2

3

我对您在这里尝试做的事情做了一些假设。我假设您想在您选择的两行之间注释代码块。这是一种使用方法GNU sed

sed -i '/response = HttpResponse()/,/return response/s/.*/#&/' file.txt
于 2012-09-25T09:40:37.580 回答
2
perl -i -ne 'if(/response = Http/../return response/){$_="#".$_}print' your_file
于 2012-09-25T11:43:38.753 回答