我有一个内容如下的文件:
{
"applications": [
{
"id": 2537302,
"name": "addressdb_prod",
"language": "dotnet",
"health_status": "unknown",
"reporting": true,
"last_reported_at": "2017-08-03T10:41:52+00:00",
"application_summary": {
"response_time": 5.04,
more content here....
and finally the following lines towards the end of the file
},
"links": {
"application_instances": [],
"servers": [],
"application_hosts": []
}
}
],
"links": {
"application.servers": "/v2/servers?ids={server_ids}",
"application.server": "/v2/servers/{server_id}",
"application.application_hosts": "/v2/application/{application_id}/hosts?ids={host_ids}",
"application.application_host": "/v2/application/{application_id}/hosts/{host_id}",
"application.application_instances": "/v2/application/{application_id}/instances?ids={instance_ids}",
"application.application_instance": "/v2/application/{application_id}/instances/{instance_id}",
"application.alert_policy": "/v2/alert_policies/{alert_policy_id}"
}
}
我想要的是运行sed
命令来删除以下部分:
{
"applications": [
从文件的开头,以及从以下部分开始到文件末尾的任何内容。
],
"links": {
答案1
假设您的文件不包含任何其他以以下开头的行,],
定义要删除的两个范围非常简单:
sed '1,/"applications": \[/d
/^[[:blank:]]*\],/,$d' yourfile