Skip to main content
added 703 characters in body
Source Link
Baba
  • 3.5k
  • 2
  • 27
  • 40

with sed:

###UPDATE

sed -e '/\/\*/ {
    /\*\// {d
        s/\/\*.*\*\///g;
        b next
    };

    :loop;
    /\*\//! {N;b
        N;
        b loop
    };
    /\*\// {d
        s/\/\*.*\*\//\n/g
    }
    :next
}'

EXAMPLE:

FILENAME:support all possible (multi line comment, data after [or and] befor, );

/*This is to print the outpute1/*comment*/
NEWLINE-------------------
NEWLINEe1/*comment*/e2
-------------------
NEWLINE/*comment*/e2
data*-------------------
e1/*com
proc print data=sashelp.cars;ment*/
run;-------------------
e1/*Creating dataset**com
ment*/e2
data abc;-------------------
set xyz;/*com
run;ment*/e2
-------------------
e1/*com
1
2
ment*/
-------------------
e1/*com
1
2
ment*/e2
-------------------
/*com
1
2
ment*/e2
-------------------

and out put####run:

$ sed -e '/\/\*/{/\*\//{d};:loop;/\*\//!{N;bf loop};/\*\//{d}}'command.sed FILENAME
proc print data=sashelp.cars;
run;e1
data abc;-------------------
set xyz;e1e2
run;-------------------
e2
-------------------
e1

-------------------
e1
e2
-------------------

e2
-------------------
e1

-------------------
e1
e2
-------------------

e2
-------------------

with sed:

sed -e '/\/\*/{/\*\//{d};:loop;/\*\//!{N;b loop};/\*\//{d}}'

EXAMPLE:

FILENAME:

/*This is to print the output
NEWLINE
NEWLINE

NEWLINE
data*/
proc print data=sashelp.cars;
run;
/*Creating dataset*/
data abc;
set xyz;
run;

and out put:

$ sed -e '/\/\*/{/\*\//{d};:loop;/\*\//!{N;b loop};/\*\//{d}}' FILENAME
proc print data=sashelp.cars;
run;
data abc;
set xyz;
run;

with sed:

###UPDATE

/\/\*/ {
    /\*\// {
        s/\/\*.*\*\///g;
        b next
    };

    :loop;
    /\*\//! {
        N;
        b loop
    };
    /\*\// {
        s/\/\*.*\*\//\n/g
    }
    :next
}

support all possible (multi line comment, data after [or and] befor, );

 e1/*comment*/
-------------------
e1/*comment*/e2
-------------------
/*comment*/e2
-------------------
e1/*com
ment*/
-------------------
e1/*com
ment*/e2
-------------------
/*com
ment*/e2
-------------------
e1/*com
1
2
ment*/
-------------------
e1/*com
1
2
ment*/e2
-------------------
/*com
1
2
ment*/e2
-------------------

####run:

$ sed -f command.sed FILENAME

e1
-------------------
e1e2
-------------------
e2
-------------------
e1

-------------------
e1
e2
-------------------

e2
-------------------
e1

-------------------
e1
e2
-------------------

e2
-------------------
Source Link
Baba
  • 3.5k
  • 2
  • 27
  • 40

with sed:

sed -e '/\/\*/{/\*\//{d};:loop;/\*\//!{N;b loop};/\*\//{d}}'

EXAMPLE:

FILENAME:

/*This is to print the output
NEWLINE
NEWLINE

NEWLINE
data*/
proc print data=sashelp.cars;
run;
/*Creating dataset*/
data abc;
set xyz;
run;

and out put:

$ sed -e '/\/\*/{/\*\//{d};:loop;/\*\//!{N;b loop};/\*\//{d}}' FILENAME
proc print data=sashelp.cars;
run;
data abc;
set xyz;
run;