Sed在大括号之间删除bash脚本中的行

时间:2013-03-08 08:00:12

标签: bash sed

我正在尝试删除带花括号的脚本中的注释和空行。 当文件没有大括号但是如果它有大括号时,下面的代码很有效,那么代码只删除注释并在其位置留下空格。

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;
   }
 }

感谢

1 个答案:

答案 0 :(得分:0)

你的脚本在zsh中完美运行。 试试这个

sed  -e 's/^#//' -e '/^[ \t]*$/d'