Skip to content

Instantly share code, notes, and snippets.

@hartwork
Created February 9, 2015 12:54
Show Gist options
  • Save hartwork/7296c477f724fb38c366 to your computer and use it in GitHub Desktop.
Save hartwork/7296c477f724fb38c366 to your computer and use it in GitHub Desktop.
Group filenames fed to stdin into wildcard patterns (e.g. "*.txt", "*.pdf")
#! /usr/bin/awk -f
# Copyright (C) 2009 Sebastian Pipping <[email protected]>
# Licensed under GPLv3 or later
# 2009-04-09
#
# Input
# one.txt
# two.pdf
# three.txt
#
# Output
# *.txt
# *.pdf
#
BEGIN {
FS = "/"
}
{
dotPartsCount = split($NF, dotParts, "\\.")
if (dotPartsCount <= 1) {
next
}
fileExtension = dotParts[dotPartsCount]
if (length(fileExtension) < 1) {
next
}
if (fileExtensionsSeenBefore[fileExtension]) {
next
}
fileExtensionsSeenBefore[fileExtension] = 1
print "*." fileExtension
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment