user13395631
user13395631

Reputation:

use sed to make all comments consistent

my file contains uneven comments:

// file1.php
        // Week 4 
        // Quiz
                               //coment3
//                     comment4
/ /comment5
      / /comment6
%comment7
%               comment8
                           %comment9
#comment10
#                     comment11
            #comment12

I want to make these comments consistent by replacing # or // with just // followed by a single space.
I have: s/[ \t]*//.
it gives me

// file1.php
// Week 4 
// Quiz
//coment3
//                     comment4
/ /comment5
/ /comment6
#comment10
#                     comment11
#comment12

Upvotes: 0

Views: 105

Answers (1)

mevets
mevets

Reputation: 10445

sed -e 's,/[[:space:]]*/,//,' -e 's,[[:space:]]*//[[:space:]]*,// ,' -e 's/[[:space:]]*\([%#]\)[[:space:]]*/\1 /'

Upvotes: 1

Related Questions