我有一个包含多个类似部分的文件
...
# PostgreSQL configuration example
#production:
# adapter: postgresql
# database: redmine
# host: localhost
# username: postgres
# password: "postgres"
# SQLite3 configuration example
#production:
# adapter: sqlite3
# database: db/redmine.sqlite3
# SQL Server configuration example
#production:
# adapter: sqlserver
# database: redmine
# host: localhost
# username: jenkins
# password: jenkins
...
我想评论/删除整个部分。
使用“SQLite3”我希望得到以下输出:
...
# PostgreSQL configuration example
#production:
# adapter: postgresql
# database: redmine
# host: localhost
# username: postgres
# password: "postgres"
# SQLite3 configuration example
production:
adapter: sqlite3
database: db/redmine.sqlite3
# SQL Server configuration example
#production:
# adapter: sqlserver
# database: redmine
# host: localhost
# username: jenkins
# password: jenkins
...
我尝试过类似的事情:
sed -i -e '/SQLite3/+1,/^\s*$/ s/^#//' FILE
...但它不起作用,因为'+1'无效。
如何在比赛结束后在线上开始射程? (我用括号和'n'尝试了几种变体,但我找不到合适的法术)
答案 0 :(得分:0)
选择完整范围,然后仅将替换命令应用于与第一个模式不匹配的行的子范围:
sed '/SQLite3/,/^$/ { /SQLite3/! s/^#// }' file
扩展了可读性:
sed '/SQLite3/,/^$/ {
/SQLite3/! {
s/^#//
}
}' file