Looking at the
awk program suggested by
gostdog74, it struck me that it might be interesting to modify that program to handle the case of nested comments. So, for what it's worth, here's my take on the code:
Code:
$ cat igor.awk
#!/bin/gawk
/\(*/ || /\*\)/ {
while (match($0,/\(\*/)) {
if (!f) printf "%s", substr($0, 1, RSTART-1)
++f
$0 = substr($0, RSTART+2)
}
while (match($0,/\*\)/)) {
(f) ? --f : 0
if (!f && (RSTART+2 < length($0))) {
print substr($0,RSTART+2)
next
}
$0 = substr($0, RSTART+2)
if (!f && !NF) printf "\n"
}
}
!f && NF {print}
Here's my test data
Code:
$ cat test.dat
This is a word (* followed by comment *)
This is a line with a (* split
comment over three
lines *)
And one with no comments
So what's this (* gonna do
if there's *) anything behind comments?
And (* sometimes (* we
*) might have
other *)
nested comments.
and the output:
Code:
$ awk -f igor.awk test.dat
This is a word
This is a line with a
And one with no comments
So what's this anything behind comments?
And
nested comments.