Searching file for pattern, output to file (BASH)

Hello,
I'm trying to write a script in Bash to assist in pentesting. Essentially I'm looking to use a script to search for some terms in a log file and then send that key information into another file.

The log files consist of HTTP and SSL information that someone creates while browsing and logging into a website. But the login information gets buried underneath all of the HTTP information.

The output for the passwords vary such as this:

&pass=password123
&passwd=password123

However the username can be found easily by using a search for %40 because all usernames that are email's show up in the log like this:

testusername%40gmail.com

Is there anyway I can take the whole line where one of the above examples show up and print that into a file?

Thanks

EDIT: (This is what I have so far, I forgot to put it in with the original post)

read -p "What file are you searching? " fname
read -p "What are you looking for? " pattern
if [ -f "$fname" ]
then
    result=$(grep -i "$pattern" "$fname")
    echo "$result"
fi

So what are you trying to extract from the logfile...the username and password information.

Exactly but I'm looking to take the whole line where the username and password is found in the log file and output it to another file. I want the whole line because it tells me what site the username and password correlates to.

I might also want the line above the line containing the usename and password as well.

Here's an example of a line in the log file that has the username and password:

.tries=1&.src=fpctx&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.lang=en-US&.bypass=&.partner=&.u=ce680od7o8okp&.v=0&.challenge=3FqbyPI8_gfTw7vxeai_eaIuZlwU&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fwww.yahoo.com%2F&.pd=fpctx_ver%3D0%26c%3D%26ivt%3D%26sg%3D&.ws=1&.cp=0&nr=0&pad=5&aad=5&login=testusername%40gmail.com&passwd=password123&.save=&passwd_raw=

The line above that included with the line containing the username and password looks like this:

2012-04-10 12:41:19,033 POST Data (login.yahoo.com):
.tries=1&.src=fpctx&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.lang=en-US&.bypass=&.partner=&.u=ce680od7o8okp&.v=0&.challenge=3FqbyPI8_gfTw7vxeai_eaIuZlwU&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fwww.yahoo.com%2F&.pd=fpctx_ver%3D0%26c%3D%26ivt%3D%26sg%3D&.ws=1&.cp=0&nr=0&pad=5&aad=5&login=testusername%40gmail.com&passwd=password123&.save=&passwd_raw=