Created
May 7, 2013 10:14
-
-
Save kalkulus/5531628 to your computer and use it in GitHub Desktop.
BASH: WordCombinator - combine dictionary words by overlapping end/start characters
This file contains hidden or 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
#!/bin/bash | |
# | |
# Author: Dusko Petrovic <[email protected]> | |
# | |
# | |
# Usage: | |
# ./wordcombinator.sh WORD OVERLAPCHARS OVERLAPEND | |
# WORD - word you are looking to combine with something | |
# OVERLAPCHARS - number of characters to combine - default 2 | |
# OVERLAPEND - 1 - overlap characters from the end - default | |
# 0 - overlap characters from the start | |
# | |
# Examples: | |
# combine word "team", overlap 2 characters from the end | |
# ./wordcombinator.sh team 2 1 | |
# | |
# combine word "hard", overlap 3 characters from the start | |
# ./wordcombinator.sh hard 3 0 | |
# | |
# Copyright 2010 Dusko Petrovic | |
# | |
# This file is part of WordCombinator.sh | |
# | |
# WordCombinator.sh is free software: you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License as | |
# published by the Free Software Foundation, either version 3 of the | |
# License, or (at your option) any later version. | |
# | |
# WordCombinator.sh is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
# General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with WordCombinator.sh. If not, see http://www.gnu.org/licenses/. | |
# Get parameters | |
searchString=$1 | |
# set default values | |
overlapChars=2 | |
overlapEnd=1 | |
if [ $# == 2 ]; | |
then | |
overlapChars=$2 | |
elif [ $# == 3 ]; | |
then | |
overlapChars=$2 | |
overlapEnd=$3 | |
fi | |
#echo $searchString | |
#echo $overlapChars | |
#echo $overlapEnd | |
#exit 0 | |
if [ $overlapEnd == 0 ] | |
then | |
# echo "from the start" | |
firstLetters=${searchString:0:$overlapChars}; | |
for i in $(grep "$firstLetters$" /usr/share/dict/words); do | |
echo $i' + '$searchString' = '${i%$firstLetters}$searchString; | |
done | |
else | |
# echo "from the end" | |
lastLetters=${searchString:(-$overlapChars)}; | |
for i in $(grep "^$lastLetters" /usr/share/dict/words); do | |
echo $searchString' + '$i' = '${searchString%$lastLetters}$i; | |
done | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment