Question

I have a file like

record
    decimal(10) roll_no /*DECIMAL(10) NOT NULL*/;
    string(25) name /*STRING(25) NOT NULL*/;
    decimal(3) marks = NULL /*DECIMAL(3) NULL*/;
end

and I want it as

record
    decimal(10) roll_no;
    string(25) name;
    decimal(3) marks = NULL;
end

Can you guys help?

I tried with awk and sed but ihad to do some manual changes at the end to get it perfect.

Was it helpful?

Solution

If it is sure that this are-one-line only comments you can use this:

sed 's~/\*.*\*/~~'

OTHER TIPS

This awk should do

awk '{sub(/ \/.*\//,x)}8' file
record
    decimal(10) roll_no;
    string(25) name;
    decimal(3) marks = NULL;
end

It replace from / to / with nothing.

Another version

awk -F" */" '{print $1";"}' file
record;
    decimal(10) roll_no;
    string(25) name;
    decimal(3) marks = NULL;
end;

Another one

awk -F" */" '{$0=$1";"}8' file

Here is the sed command which can handle if there are not one-line only comments:

sed ':a;$!{N;ba};s~/\*[^*/]*\*/~~g' file

Explanation

  • ':a;$!{N;ba} read the whole file into pattern
  • s~/\*[^*/]*\*/~~g replace any contents between /* and */
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top