Home > Enterprise >  Replacing html content using sed and regex
Replacing html content using sed and regex

Time:06-30

I am trying to replace the content of some HTML content using sed in a bash script. For some reason I'm not getting the proper result as it's not replacing anything mainly the regex part

HTML i want to replace

<h3 >For the Most Complex Heroines Animation
<h3 >The Psychology Behind Sibling

to

 head For the Most Complex Heroines Animation
 head The Psychology Behind Sibling

i used

  sed -e 's/<h3 >/head/g'

mainly ([a-b0-9]) this part is getting failed in execution , i must be missing something out,i want to get it more specific , i have "<p >How many words can" i want to substitute it to 'tail ' and have many more other tags . The regex part is giving me the pain

CodePudding user response:

You need to use \ , unless you use sed -E

  • \ is a valid quantifier in the (default) Basic regular expressions
  • is a valid quantifier in Extended regular expressions

CodePudding user response:

Using sed

$ sed 's/.*-[[:alnum:]]\ ">/head /' input_file

Output

head For the Most Complex Heroines Animation
head The Psychology Behind Sibling
  • Related