| Line | |
|---|
| 1 | # tee.awk --- tee in awk
|
|---|
| 2 | #
|
|---|
| 3 | # Arnold Robbins, [email protected], Public Domain
|
|---|
| 4 | # May 1993
|
|---|
| 5 | # Revised December 1995
|
|---|
| 6 |
|
|---|
| 7 | BEGIN \
|
|---|
| 8 | {
|
|---|
| 9 | for (i = 1; i < ARGC; i++)
|
|---|
| 10 | copy[i] = ARGV[i]
|
|---|
| 11 |
|
|---|
| 12 | if (ARGV[1] == "-a") {
|
|---|
| 13 | append = 1
|
|---|
| 14 | delete ARGV[1]
|
|---|
| 15 | delete copy[1]
|
|---|
| 16 | ARGC--
|
|---|
| 17 | }
|
|---|
| 18 | if (ARGC < 2) {
|
|---|
| 19 | print "usage: tee [-a] file ..." > "/dev/stderr"
|
|---|
| 20 | exit 1
|
|---|
| 21 | }
|
|---|
| 22 | ARGV[1] = "-"
|
|---|
| 23 | ARGC = 2
|
|---|
| 24 | }
|
|---|
| 25 | {
|
|---|
| 26 | # moving the if outside the loop makes it run faster
|
|---|
| 27 | if (append)
|
|---|
| 28 | for (i in copy)
|
|---|
| 29 | print >> copy[i]
|
|---|
| 30 | else
|
|---|
| 31 | for (i in copy)
|
|---|
| 32 | print > copy[i]
|
|---|
| 33 | print
|
|---|
| 34 | }
|
|---|
| 35 | END \
|
|---|
| 36 | {
|
|---|
| 37 | for (i in copy)
|
|---|
| 38 | close(copy[i])
|
|---|
| 39 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.