aboutsummaryrefslogtreecommitdiff
path: root/challenge-001/paulo-custodio/awk/ch-1.awk
blob: 001f74cd238da1388d40c46f901392a5622cfc11 (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
#!/usr/bin/gawk

# Challenge 001
#
# Challenge #1
# Write a script to replace the character 'e' with 'E' in the string
# "Perl Weekly Challenge". Also print the number of times the character 'e'
# is found in the string.

function join(array, start, end, sep,    result, i) {
    if (sep == "")
       sep = " ";
    else if (sep == SUBSEP) # magic value
       sep = "";
    result = array[start];
    for (i = start + 1; i <= end; i++)
        result = result sep array[i];
    return result;
}

function alen(a, i, k) {
    k = 0;
    for(i in a) k++;
    return k;
}

BEGIN {
    text = join(ARGV, 1, alen(ARGV));
    print gsub(/e/, "E", text) " " text;
    exit 0;
}