Variables into SED or AWK and multiple commands

Hello I am hoping you may help.

I am not sure how to go about this exactly, I know the tools but not sure how to make them work together.

I have two SED commands that I would like to run in a shell script. I would like to take
the manual input of a user (types in when prompted) to be used as the variables.

Firstly I am not sure how to build the script with cat or loop statements
Secondly how to place a variable inside a SED or NAWK statement so it can be used by those commands.
Thirdly how to produce a temporary file that is date-stamped.

I have a general summary of what I am trying to do below.
#!/usr/bin/
echo "enter name of file" (variable AAAA)
echo "enter first search string1 (variable yyyy)
echo " enter a second search string that searches the file along with string1 ? (variable zzzz)
user types yes, then
enter data
user types no,
then continue with command. sed (filename) variableAAAA > newfilename (newfile with date and time stamp = testfileddmmyyhhmm)
wait 3 seconds
then newfilename sed -e '/./{H;$!d;}' -e 'x;/variableyyyy/'d'
end

Just learning this and hoping you may help.
Thankyou

I guessed a bit, and this code isn't complete, so it should get you started:

#!/usr/bin/env ksh
# the previous line can be replaced with #!/usr/bin/env bash 
# if you prefer to use bash

printf "enter filename: "
read filename
printf "do you want to enter data [yes|no] "
read ans
case $ans in
    y*|Y*)
            printf "enter search data: "
            read data                       # your description didnt indicate what to do with data
            ;;
    n*|N*)
            ;;              # just continue

    *)      printf "invalid reply; expected Y(es) or N(o)\n"
            exit 1
            ;;
esac

#
#  couldn't tell if this needed to be executed only if user entered no, or in all cases
#
date=$( date +%Y%m%d$H%M%S )                # date for the filename in a variable should it need to be used again
newfilename="testfile.$date"                # complete filename
sed ..... <$filename >$newfilename          # incomplete command, not sure what you need the sed to do
sleep 3
sed   -e '/./{H;$!d;}' -e "x;/$data/d" <$netfilename >not-sure-what-file-for-here

You didn't indicate what to do with the data entered if the user answered 'yes' to the second prompt. I also wasn't sure if a no response was the only time the sed commands were to be executed, or if no was just to avoid entering the data and the sed commands would always be executed.

Thankyou
Yes sorry, the command you mentioned
sed ..... <$filename >$newfilename # incomplete command, not sure what you need the sed to doI am using a SED command to delete a blank lines in an existing file and it opens a newfile with the new data. I then run it through another SED command which extracts the searched variable(s) that the user inputs. So using

sed '/NZDT/{N;s/\n//;}' access.log > testfile2003121130
then using another SED command with a variable (or two variables) which have been entered by the user (variableyyyy) - putting that in the next SED command and running that on the newfile testfile2003121130. .
so
user inputs first entered data when prompted "john"
user is prompted again if they want to enter another criteria to search at the same time "smith" (search for john smith) - thats not the actual text I am searching for just an example.

sed '/NZDT/{N;s/\n//;}' access.log > testfile2003121130
cat testfile2003121130 | sed -e '/./{H;$!d;}' -e 'x;/variableyyy/!d'
print the result to screen.
I am hoping to automate this rather than put in two separate commands.

Hope that may clarify what I am trying to do.
Thanks again regards

OK, you need to have the user enter a filename, and then a one or two word search string. The file is then searched and all lines matching the search string ('John' or 'John Smith') are extracted and written to a new file tempfile.YYYYMMDD; right?

If that's accurate, then I think this is all you need:

#!/usr/bin/env ksh
printf "enter filename: "
read filename
printf "enter search data (e.g. john or john smith) "
read search_string
grep "$search_string" $filename >testfile.$(date +%Y%m%d$H%M%S)

Thankyou that description you gave is exactly right, the user enters the filename to be searched followed by the text they wan to search for.

what I found is the SED commands do strip out in the manor I want but I have to run them individually and manually. The first SED command strips out the Blank lines that are in the file which presently separate the access.log individual log data from the date line in the logs.
The second SED command searches for the entered search text that the user enters and strips out the entire paragraph where it is contained.
So I am hoping to run these two in the same script with the user just inputting the filename and search text- else that grep command would be very good .
Any help with this is very much appreciated.
Regards again.