While loop with input in a bash script

I have the following while loop that I put in a script, demo.sh:

while read rna; do
      aawork=$(echo "${rna}" | sed -n -e 's/\(...\)\1 /gp' | sed -f rna.sed)
      echo "$aawork" | sed 's/ //g'
      echo "$aawork" | tr ' ' '\012' | sort | sed '/^$/d' | uniq -c | sed 's/[ ]*\([0-9]*\) \(.*\)/\2: \
\1/'

This is how I use it in a terminal:

./demo.sh < input.txt

Now I need to make this bash code (the above while loop) part of another script, master.sh, but I am stuck as how to pass the input file to it.

I appreciate your help.

Without seeing your other script (and how you invoke it), any guess that we could make would likely be wrong.

But, if nothing else in your other script reads from its standard input, sourcing demo.sh in your other script or physically including the text of demo.sh it in your other script should work.

This is my master.sh script:

#!/bin/bash                                                                                             
#check to see if there is an input file:                                                                
if [ "$#" -lt 1 ]
then
  echo "Usage: $0 input_file ..."
  exit 1
fi

#Check if the file is empty or not                                                                      
file=$1
if [[ -s $1 ]]                   # if not empty:
then
  echo ""
  echo "**** $file has data."
  cat $1 | sed 's/>/\n>/g' > temp1.txt
  cat temp1.txt | sed '/^>/ d' > temp2.txt
  awk '!NF{if(++n <=1) print; next}; {n=0; print}' < temp2.txt > dna.out
  awk '/./{printf "%s",$0;next} {print "\n";} END{if (/./)print""}' dna.out > DNA.out
  echo "**** Number of DNA sequences:"
  grep -cve '^\s*$' DNA.out
  echo "**** Mumber of empty lines:"
  grep -ce '^\s*$' DNA.out
  echo ""
  #Remove duplicate empty lines:                                                                        
  awk '!NF{if(++n <=1) print; next}; {n=0; print}' < temp2.txt > DNA.out                               
  echo "**** DNA.out created (removed FASTA header)"
  #convert to mRNA and remove temp1, temp2 to avoid confusion                                           
  tr ACGT ACGU < DNA.out > RNA.out
  echo "**** RNA.out created (T -> U)"
  echo ""
  rm temp1.txt temp2.txt
  moved to conversion:                                                                                
  while read rna; do                                                                                  
      aawork=$(echo "${rna}" | sed -n -e 's/\(...\)\1 /gp' | sed -f rna.sed)                          
      echo "$aawork" | sed 's/ //g'                                                                   
      echo "$aawork" | tr ' ' '\012' | sort | sed '/^$/d' | uniq -c | sed 's/[ ]*\([0-9]*\) \(.*\)/\2\
: \1/'                                                                                                  
  done                                                                                                
  echo "**** creating AminoAcid from DNA:"
  ./convert_dna.sh < DNA.out > DNA_AminoAcid.out
  echo "**** Amino Acids from DNA saved in DAN_AminoAcid.out."
  echo "**** creating AminoAcid from RNA:"
  ./convert_rna.sh < RNA.out > RNA_AminoAcid.out
  echo "**** Amino Acids from RNA saved in RAN_AminoAcid.out."
  echo ""

else    # if the file is empty.                                                                         
  echo "**** $1 has no data, or file does not exist."
  echo "**** done!"
  echo ""
#clean the FASTA file and remove all lines starting with >, adding a new line first to avoid mixing all DNA samples:                                                                                           
fi;

convert_dna.sh and convert_rna.sh are two scripts that contain the while loop I mentioned in my first post. One with dna.sed and the other with rna.sed.

My question is how to add the while loop two times one with the dna.sed and the other one with rna.sed.

Use redirection: while ...; do ...; done < input_file