0

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?

myoplabo
  • 23
  • 4

1 Answers1

3

With GNU sed:

sed -i 's|^// ||' file
Cyrus
  • 84,225
  • 14
  • 89
  • 153