Skip to main content

CLI Tricks: Spongebob Sarcasm in awk

Sometimes you want to turn some text into "sarcastic Spongebob" text so this little fragment of awk will make that transformation for you:

#!/usr/bin/awk -f
BEGIN { srand() }
{
    n = split($0, a, //)
    for (i=1; i<=n; i++) {
        c=a[i]
        printf("%c", rand() < 0.5 ? toupper(c) : tolower(c))
    }
    print ""
}
sarcasm.awk

To use it, you can either invoke it directly, then copy and paste the results:

echo spongebob sarcasm | sarcasm.awk
sPongEbOb SaRcasM
sarcasm.awk file.txt > output.txt

Or, you can manipulate the contents of the clipboard:

xsel -ob | sarcasm.awk | xsel -ib

If you don't have xsel you might have xclip on Linux or the BSDs, and on MacOS, you might have pbcopy/pbpaste that you can use instead.