Home > front end >  sed - how can I cover optional space?
sed - how can I cover optional space?

Time:12-16

Probably this is a dumb question but here we go! I am using sed to remove a content from file and sometimes it doesnt have a space character:

myfile

resource "love" {
   ...
}

myfile2

resource "love"{
   ...
}

My command:

sed -i '' -e '/resource "love" {/,/}/d;/resource "love"{/,/}/d' 

Do you have another option to consider that space as optional character and cover both situations instead of copy/paste sed instruction?

CodePudding user response:

With perl:

perl -i -0pe 's/ressouce "love".*?\}//s' file

CodePudding user response:

Match zero or more using sed

$ sed -i "" '/resource "love" *{/,/}/d' input_file
  • Related