aboutsummaryrefslogtreecommitdiff
path: root/challenge-131/abigail/awk/ch-2.awk
blob: 5215d94acfd80cabf2ee97013538c4a292b24674 (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
32
33
34
35
#!/usr/bin/awk

#
# See ../README.md
#

#
# Run as: awk -f ch-2.awk < input-file
#

NR == 1 {
    n = split ($0, delims, "")
}

NR == 2 {
    m = split ($0, chars, "")
    out1 = ""
    out2 = ""
    for (i = 1; i <= m; i ++) {
        for (j = 1; j <= n; j += 2) {
            if (delims [j] == chars [i]) {
                out1 = out1 delims [j]
                break
            }
        }
        for (j = 2; j <= n; j += 2) {
            if (delims [j] == chars [i]) {
                out2 = out2 delims [j]
                break
            }
        }
    }
    print out1
    print out2
}