Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I kind of new to Linux and i was recently grepping the Cisco firewall logs on CentOS server, I was grepping on the timestamp which gave me undesired results
i was using the following command
grep 17:0 /boot/*
and i was getting the following output. I was looking to for logs starting from 17:00 hrs and not 00:17 0r 01:17
Sep 4 00:17:08 x.x.x.x.x %FWSM-6-302014
Sep 4 00:17:08 x.x.x.x.x %FWSM-6-302013
My question is how can i modify this grep command to get exact results for logs matching 17:00 hrs onwards.
Since we have included a space we don't want to search on file named 17:0 and other files (\boot\*) . We want to search the on entire string which is ( 17:0)
Grep
Grep allows the unquoted string, but it is limited by what BASH will let pass.
Use quotes when you want to be exact, or anytime you are unsure.
You will still have problems with some characters that are specially interpreted.
Then you will have to backslash characters to get the search you want.
Example:
>> grep " 17:00" *
- without the quotes, the space would not be in the search string. This applies to arbitrary strings.
>> grep "The quick brown fox went up the twisty road" *
Example:
>> grep " fred[" *
- will not work, will get an error message
>> grep " fred\[" *
- backslashed to get the square bracket into the search string as it is.
Advanced:
>> grep " 17:00" * | grep " something else"
- to apply more than one grep test to a line
Try this:
>> grep " 1[789]:00" *
and look into rgrep and egrep.
Last edited by selfprogrammed; 09-06-2014 at 04:42 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.