grep a url on a specific line

I'm grepping spam from my application logs.

I'm looking for the one line URL spam.  It will always show up on my third line

---------
blah
blah
http://spam.com/url.html
----------

How do I grep only the third line and how to I grep to see if a URL exists?

md168Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

md168Author Commented:
I figured out how to find the specific line: head -3 spam.txt | tail -1

Now, I need to search for a URL
0
wesly_chenCommented:
#!/bin/sh

LOG_FILE=/path-to-application-log

STRING=`head -3 $LOG_FILE | tail -1`
if [ "$STRING" =~ "http" ]
then
   echo $STRING
fi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
farzanjCommented:
Try this one

sed -n 3p spam.txt | grep http

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

farzanjCommented:
Or try this one even simpler and more efficient
sed -n  3,/http/p

Open in new window

0
md168Author Commented:
I couldn't get the sed to work.  I'll use the wesly's script.  Thanks.
0
farzanjCommented:
Both the sed work

What is the error message
0
wesly_chenCommented:
Hi farzanj, I believe your second one is
sed -n 3,/http/p spam.txt
0
farzanjCommented:
Hi Wesly,
Yes, I forgot the file name but the first one worked too.  It had filename as well.  And both DO work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.