Reputation: 73
I have a yaml file with words and some characters.
version: "5.0.0"
migratorConfigs:
-
name: "SchemaMigrator"
order: 1
parameters:
location: "step1"
schema: "identity"
-
version: "5.1.0"
migratorConfigs:
-
name: "IdentityDataCleaner"
order: 1
parameters:
schema: "identity"
-
name: "SchemaMigrator"
order: 2
parameters:
location: "step1"
schema: "identity"
-
name: "RegistryDataMigrator"
order: 6
parameters:
schema: "um"
I need to remove only the dash(-) prior to name: "RegistryDataMigrator"
. There were many dashes and I just wanted to remove the last one.
Any ideas please?
Upvotes: 1
Views: 53
Reputation: 58420
This might work for you (GNU sed):
sed 'N;/RegistryDataMigrator[^\n]*$/!P;D' file
Create a two line window throughout the length of the file using the N;...;P;D
method and do not print the first line of the window if the last line of the window contains RegistryDataMigrator
.
Upvotes: 2
Reputation: 73
I just found this answer from
http://www.theunixschool.com/2012/06/sed-25-examples-to-delete-line-or.html
sed -i -n '/RegistryDataMigrator/{x;d;};1h;1!{x;p;};${x;p;}' /home/user1/Documents/migration.yaml
And it works for me!
Upvotes: 3