Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

I'm trying to write a program that replaces a scss function call and doubles the input e.g.

input

.color {
  margin: spacing(1.5);
}

.test {
  margin: spacing(2) spacing(3);
}

output

.color {
  margin: spacing(3);
}

.test {
  margin: spacing(4) spacing(6);
}

This almost works

gawk '{
  line = $0
  if (match(line, /spacing\(/)) {
    print gensub(/spacing\(([0-9\.]+)\)/, "spacing(\\1 * 2)", "g", line)
  } else {
    print line
  }
}' ./test.scss > ./test2.scss
// test2.scss

.color {
  margin: spacing(1.5 * 2);
}

.test {
  margin: spacing(2 * 2) spacing(3 * 2);
}
  • Can you multiply by two rather than appending " * 2" to the match?
  • How can you run on all **/*.scss files and replace them?
@markbrown4

This comment has been minimized.

Copy link
Owner Author

markbrown4 commented Mar 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.