If it is sure that this are-one-line only comments you can use this:
sed 's~/\*.*\*/~~'
문제
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.
해결책
If it is sure that this are-one-line only comments you can use this:
sed 's~/\*.*\*/~~'
다른 팁
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
':a;$!{N;ba}
read the whole file into patterns~/\*[^*/]*\*/~~g
replace any contents between /* and */