Longest Word in Awk

Published on 14 April 2025 (Updated: 16 April 2025)

Welcome to the Longest Word in Awk page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

function usage() {
    print "Usage: please provide a string"
    exit(1)
}

function longest_word(s,  len, max_len, k) {
    split(s, arr, /\s+/)
    max_len = 0
    for (k in arr) {
        len = length(arr[k])
        if (len > max_len) {
            max_len = len
        }
    }

    return max_len
}

BEGIN {
    if (ARGC < 2 || !ARGV[1]) {
        usage()
    }

    print longest_word(ARGV[1])
}

Longest Word in Awk was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.