summaryrefslogtreecommitdiff
path: root/awklib/eg/prog/awksed.awk
blob: d9f177175ca6cfd25372ede9e757220b58429f72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# awksed.awk --- do s/foo/bar/g using just print
#    Thanks to Michael Brennan for the idea
#
# Arnold Robbins, arnold@skeeve.com, Public Domain
# August 1995

function usage()
{
    print "usage: awksed pat repl [files...]" > "/dev/stderr"
    exit 1
}

BEGIN {
    # validate arguments
    if (ARGC < 3)
        usage()

    RS = ARGV[1]
    ORS = ARGV[2]

    # don't use arguments as files
    ARGV[1] = ARGV[2] = ""
}

# look ma, no hands!
{
    if (RT == "")
        printf "%s", $0
    else
        print
}