我正在尝试删除带有花括号的脚本中的注释和空行。以下代码在文件没有大括号时运行良好,但如果文件有大括号,则代码仅删除注释并在其位置留下空格。
sed  -e 's/#.*$//' -e '/^$/d' file >> file 
在不删除空行的情况下,输出结果如下
 more stuff above here
 location ~ \.php$ {
     root     /usr/share/nginx/html;
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
   }
 location ~ /\.ht {
     deny  all;
   }
 }
谢谢