hi this is a homework assignment i need some help with
it mostly works.
script file
#!/usr/bin/env bash
#create dictionary file
grep -E '.{3}' /usr/share/dict/british-english > db.txt
#create remove_word to test file
touch removeW.txt
#palindrome function
palin()
{
sed 's/[0-9]*//g;s/[/\._-]//g'\
|tr -d '[[:punct:][:digit:]@]' \
| sed -E -e '/^(.)\1+$/d' \
| tr -s '[[:space:]]' \
| tr '[[:space:]]' '\n'
}
paste <(palin <"$1") <(palin <"$1" | rev) \
| awk '$1 == $2 && (length($1) >= 3) { print $1 }' \
| sort | uniq -ic > done.txt
#removes repeated letters
awk '{l=$0; if (length($2)!=gsub(substr($2,1,1), "", $2)) print l}' done.txt > finish.txt
#compares text files to remove words
grep -vwF -f db.txt finish.txt > removeW.txt|
grep -vwF -f removeW.txt finish.txt|
awk '!/ere|eke/'
#rm db.txt finish.txt removeW.txt done.txt
i can get this command to work
./script textfile
and it gives mostly the correct output.
but i also want to be able to invoke a command such as
cat textfile | script > outputfile
i'm not sure where to add the arguments in the script. I tried adding parameters on the paste line but get errors that file/directory not existing. I also tried an if statement, something i found.
if (($#)) ; then
process "$1"
else
cat | process
fi
tried different statements but it didn't work.
i'm using ubuntu lastest version i think.
any hints or help would be great thank you.