1

I am using sed to remove comment characters at the beginning using s/${pn_ere}//. The delimiter ends up being a problem for C++ code when I have the line start being //.

What alternative to / could I use that would be safe to use for most programming languages?

   sed -n "/$beg_re/,/$end_re/ {
      /$beg_re/d ; /$end_re/z; s/${pn_ere}// ; p`

s/${pn_ere}// but have to replace the use of / and use another delimiter. In this way I can handle C++ code where comments start with //.

Dilna
  • 405
  • 1
  • 6
  • See: [Escaping forward slashes in sed command](https://stackoverflow.com/q/40714970/3776858) – Cyrus Jan 31 '23 at 08:15

1 Answers1

0

You could use "_" for example.

See here for more ideas.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • I also wonder what to do with things like `/$beg_re/d` when the `beg_re` pattern also starts with `//`. – Dilna Jan 31 '23 at 08:02
  • Use e.g. `\|$beg_re|d` – Cyrus Jan 31 '23 at 08:12
  • Would I not need an escape for the second `|` ? – Dilna Jan 31 '23 at 08:28
  • I actually think that I would be fine using `/`. Consider `beg_ere="^[[:space:]]*(\/\/)[[:space:]]+"` , then there should be no problem with `/$beg_ere/d` or with `s/${beg_ere}//`. Am I right? – Dilna Jan 31 '23 at 08:32