Reputation: 983
Using a linux bash or command line, i need to find certain string in a file and delete that line and the lines until white space.
My file:
geo_ws:
resource: "@GeoWSBundle/Controller/"
type: annotation
prefix: /
mappublic:
resource: "@MapPublicBundle/Controller/"
type: annotation
prefix: /map/ws
webpublic:
resource: "@WebPublicBundle/Controller/"
type: annotation
prefix: /public
map:
resource: "@MapBundle/Controller/"
type: annotation
prefix: /map
geo:
resource: "@GeoBundle/Controller/"
type: annotation
prefix: /geo
ws:
resource: "@WSBundle/Controller/"
type: annotation
prefix: /ws
web:
resource: "@WebBundle/Controller/"
type: annotation
prefix: /
So i need to find i.e "map:", and clear all those 4 lines until next white line.
I've tried using seed, but i just can't figure it out.
Upvotes: 0
Views: 57
Reputation: 11216
Using gawk
awk -vRS= '{ORS=RT?RT:"\n"}!/^map/' file
geo_ws:
resource: "@GeoWSBundle/Controller/"
type: annotation
prefix: /
webpublic:
resource: "@WebPublicBundle/Controller/"
type: annotation
prefix: /public
geo:
resource: "@GeoBundle/Controller/"
type: annotation
prefix: /geo
ws:
resource: "@WSBundle/Controller/"
type: annotation
prefix: /ws
web:
resource: "@WebBundle/Controller/"
type: annotation
prefix: /
Upvotes: 2
Reputation: 33307
An empty record separator indicates that records are delimited by blank lines:
$ awk -v RS='' -v ORS='\n\n' '!/^map/' file
geo_ws:
resource: "@GeoWSBundle/Controller/"
type: annotation
prefix: /
webpublic:
resource: "@WebPublicBundle/Controller/"
type: annotation
prefix: /public
geo:
resource: "@GeoBundle/Controller/"
type: annotation
prefix: /geo
ws:
resource: "@WSBundle/Controller/"
type: annotation
prefix: /ws
web:
resource: "@WebBundle/Controller/"
type: annotation
prefix: /
Upvotes: 2