Using cat and pipeline to execute script

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.

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.