unroll.awk 423 B

1234567891011121314151617181920
  1. # This filter requires one command line option of form -vN=n
  2. # where n must be a decimal number.
  3. #
  4. # Repeat each input line containing $$ n times, replacing $$ with 0...n-1.
  5. # Replace each $# with n, and each $* with a single $.
  6. BEGIN {
  7. n = N + 0
  8. }
  9. {
  10. if (/\$\$/) { rep = n } else { rep = 1 }
  11. for (i = 0; i < rep; ++i) {
  12. tmp = $0
  13. gsub(/\$\$/, i, tmp)
  14. gsub(/\$#/, n, tmp)
  15. gsub(/\$\*/, "$", tmp)
  16. print tmp
  17. }
  18. }