Created
February 9, 2015 12:54
-
-
Save hartwork/7296c477f724fb38c366 to your computer and use it in GitHub Desktop.
Group filenames fed to stdin into wildcard patterns (e.g. "*.txt", "*.pdf")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 | |
# | |
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