Domanda

I am using this to remove the multiline comments.

awk '/^--/ {next} /^\/\*/ && /\*\/$/{next} /^\/\*/{c=1;next} /\*\/$/{c=0;next} !c{FS="--|\/\*";a=$1;FS="\\*\\/";a=a$2;$0=a;print}' filename

Input is like this

aaaaaaa
/*bbbbb*/
ccccccc
/*bbbbb
bbbbbb*/
ddddd

I want it to be like

aaaaaaa 

ccccccc


dddddd

but im getting

aaaaaaa
ccccccc
ddddddd

Can anyone pls help me ....

Thanks

È stato utile?

Soluzione

This awk may be the way to go:

awk '/\/\*|\*\// {$0=""}1' file
aaaaaaa

ccccccc


ddddd

It just replace line with /* or */ with nothing.


If the bbbbbb goes over more than one start/stop line, like this:

cat file
aaaaaaa
/*bbbbb*/
ccccccc
/*bbbbb
bbbbbb
bbbbbb*/
ddddd

And you would like to remove all from /* to */ and not only line with these tags:

awk '/^\/\*/ {f=1} {print f?"":$0} /\*\/$/ {f=0}' file
aaaaaaa

ccccccc



ddddd

Altri suggerimenti

Your code makes several assumptions about how comments are formatted. I am going to assume that your assumptions are correct for your code and just supply the missing blank lines:

$ awk '/^--/ {next} /^\/\*/ && /\*\/$/{print ""; next} /^\/\*/{c=1;print "";next} /\*\/$/{c=0;print "";next} !c '  filename
aaaaaaa

ccccccc


ddddd
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top