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