-1

I have files that have a header file that I need to remove.

/***....*
.
.
.
***.....*/

It is a block like this.

I have used a sed command to remove this block.

sed -i '0,/^\/*\*/d' filename

It only removes the first line of the block comment (e.g) /***....*

and I wish for it to remove the whole block.

I have tried using:

sed -i '/^.*\/\/*/d' filename, but that removes all occurrences of /*...*/

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • `sed -i '1,/^\**\/$/d' file`? – Cyrus Jul 26 '19 at 02:09
  • This might help: [The Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/3776858) – Cyrus Jul 26 '19 at 02:10
  • I believe the GCC compiler is the best tool for the job. Also see [How can I delete all /* */ comments from a C source file?](https://stackoverflow.com/q/1714530/608639), [Removing c-style comments with sed](https://unix.stackexchange.com/q/503784), [Remove multi-line comments](https://stackoverflow.com/q/13061785/608639), [Remove comments from C/C++ code](https://stackoverflow.com/q/2394017/608639), [Remove C and C++ comments using Python?](https://stackoverflow.com/q/241327/608639) and friends. – jww Jul 26 '19 at 03:07

1 Answers1

0

This awk will remove the block:

cat file
Beginning
/***....*
.
.
.
***.....*/
End of block
Some data

awk '/^\/\*\*/ {f=1} !f; /^\*\*/ {f=0}' file
Beginning
End of block
Some data

/^\/\*\*/ {f=1} If line starts with /** set flag f to 1
!f; If flag is not set print the line
/^\*\*/ {f=0} if line starts with ** clear flag f

Jotne
  • 40,548
  • 12
  • 51
  • 55