1825775 Members
2142 Online
109687 Solutions
New Discussion

Sed query

 
SOLVED
Go to solution
NOreen Merrick
Frequent Advisor

Sed query

Hi Guys,

I just want to use sed as a search function on a file instead of grep.

I want to seach for all instances of "Authentication Failure" in the syslog.log file.

I know how to search and replace but can't seem to do the search.
OS is HP-UX
Any help is most appreciated.

Thanks,

N
9 REPLIES 9
melvyn burnard
Honored Contributor

Re: Sed query

posted in wrong forum, moved to more appropriate forum
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Sundar_7
Honored Contributor
Solution

Re: Sed query


This should work.

sed -n '/Authenication Failure/p' /var/adm/syslog/syslog.log

Learn What to do ,How to do and more importantly When to do ?
James R. Ferguson
Acclaimed Contributor

Re: Sed query

Hi Noreen:

# sed -ne '/Authentication Failure/p' /var/adm/syslog/syslog.log

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: Sed query

> I just want to use sed as a search function
> on a file instead of grep.

Why?

Q: I want to use a hammer as a screwdriver,
but it keeps damaging my screws. What should
I do?

A: Use a screwdriver.
Peter Godron
Honored Contributor

Re: Sed query

Noreen,
how about:
sed -n "1,$ s/Authentication Failure/Authentication Failure/p" data.lis

what is wrong with grep ?
James R. Ferguson
Acclaimed Contributor

Re: Sed query

Hi (again) Noreen:

I would have to agree with Steven, too. If you sole objective is to find lines where you match a pattern, then 'grep' is probably the simplest tool to use.

The value of 'sed' (or 'awk' or Perl) begins to appear if you want to match *ranges* of lines with patterns or when you want to extract pieces of lines that have a matching pattern. For example, if you wanted to print lines in a file that began with the pattern 'begin' and ended with the pattern 'end', using 'sed' you could do:

# sed -ne '/^begin/,/^end/p' file

Regards!

...JRF...
NOreen Merrick
Frequent Advisor

Re: Sed query

Hi Guys,

thanks they all work. I don't really want to use Sed at all , Grep is fine for me but am doing some "exercises" on grep and that was one of the questions!! Hope i'm not wasting any valuable admin time.

N

James R. Ferguson
Acclaimed Contributor

Re: Sed query

Hi (again) Noreen:

The question is not a waste of our time, but points for the efforts to respond *are* appreciated.

Regards!

...JRF...
NOreen Merrick
Frequent Advisor

Re: Sed query

Answered and points assigned, thanks.