myoplabo
myoplabo

Reputation: 23

sed command to uncomment lines of code

Working on a build automation script and we're trying to take an input from a file called code.js like this:

var foo = {};

// var bar = 1;
// var fooBar = 2;
// var barFoo = 3;

And when we're done, have an output with the commented lines now uncommented with no leading spaces like this:

var foo = {};

var bar = 1;
var fooBar = 2;
var barFoo = 3;

We're trying to get the transformation saved back to code.js too.

So far we've tried this sed command, but our sed is no so good:

sed -i '' -e's/\*\//\n&/g' code.js

We tried using awk as well, but the leading space remains and it seems to work on the terminal, but not in the automation script for some reason:

awk '{sub(/\/\//,""); print}' code.js

We'd prefer to use sed, since we have a few sed inplace replacement commands working so far already. How can we do this in sed?

Upvotes: 0

Views: 793

Answers (1)

Cyrus
Cyrus

Reputation: 88766

With GNU sed:

sed -i 's|^// ||' file

Upvotes: 3

Related Questions