Ubuntu 用Sed替换带回车的线路

Ubuntu 用Sed替换带回车的线路,ubuntu,sed,Ubuntu,Sed,我想更改以下文件: authorize { update request { Monthly-Usage = "%{sql:SELECT COALESCE((SUM(`acctoutputoctets`)), 0) FROM radacct WHERE `username`='%{User-Name}' AND Month(acctupdatetime)=(Month(NOW())) AND Year(acctupdatetime)=Year(NO

我想更改以下文件:

authorize {
        update request {
                Monthly-Usage = "%{sql:SELECT COALESCE((SUM(`acctoutputoctets`)), 0) FROM radacct WHERE `username`='%{User-Name}' AND Month(acctupdatetime)=(Month(NOW())) AND Year(acctupdatetime)=Year(NOW())}"
        }

    filter_username
    etc


}
这样就好像删除了这个更新请求{…}

authorize {

    filter_username
    etc
}
我查阅了一些示例,得出了以下结论,但不起作用:

sed -i 'N; s/update request {\nMonthly-Usage = "%{sql:SELECT COALESCE((SUM(`acctoutputoctets`)), 0) FROM radacct WHERE `username`='"'"'%{User-Name}'"'"' AND Month(acctupdatetime)=(Month(NOW())) AND Year(acctupdatetime)=Year(NOW())}"\n}//g' /etc/freeradius/3.0/sites-enabled/default

这可能适用于GNU sed:

sed '/^authorize {$/,/^}$/c\authorize {\n ...\n}' file

使用范围来更改文件。

文件中多次出现授权或更新请求时,是否需要保持其他请求不变?为什么不在你展示的时候用空白模板重新创建一个新文件?祝你好运。这个有效:awk'/^}/{f=0}!f/授权{/{f=1}。检查更多详细信息。@shellter是有多个更新请求,但只有一个授权{。Thanks@slayedbylucifer遗憾的是,这行不通。授权中还有其他东西现在也被删除了。抱歉,我没有解释清楚。这个…只表示我想保留更多的东西。我只想删除更新请求{…}