LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-05-2016, 12:47 PM   #1
dthims
Member
 
Registered: Mar 2003
Posts: 48

Rep: Reputation: 1
expected results not produced by grep


cat /var/log/mail.log |grep 'connect from unknown[192.168.1.10]' - comes up empty
cat /var/log/mail.log |grep 'connect from unknown' - this works, but too many to sift thru
tia
 
Old 02-05-2016, 01:03 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,360

Rep: Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001
Quote:
Originally Posted by dthims View Post
cat /var/log/mail.log |grep 'connect from unknown[192.168.1.10]'
That is looking for the string "connect from unknown" immediately (with no intervening space) followed by one of the characters from the set "012689." . The square brackets and "." are all special to grep. You need to either escape them with a backslash or use the "-F" (--fixed-strings) option in grep.
Code:
cat /var/log/mail.log |grep 'connect from unknown \[192\.168\.1\.10\]'
# or
cat /var/log/mail.log | grep -F 'connect from unknown [192.168.1.10]'
 
1 members found this post helpful.
Old 02-05-2016, 01:16 PM   #3
dthims
Member
 
Registered: Mar 2003
Posts: 48

Original Poster
Rep: Reputation: 1
thnx so much. it was perfect
 
Old 02-05-2016, 02:11 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,767

Rep: Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050
Grep is also designed to read a file directly, so you can ditch cat too
Code:
grep -F 'connect from unknown [192.168.1.10]' /var/log/mail.log
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: LQ Poll Results Expected and Unexpected LXer Syndicated Linux News 0 02-08-2015 01:10 PM
LXer: id Software: Linux Hasn't Produced Positive Results LXer Syndicated Linux News 6 08-06-2012 12:54 PM
getent not returning expected results anirbanz Linux - Software 0 01-10-2006 09:44 PM
difference between distro produced by group vs. produced by single person lostsoul Linux - General 2 04-08-2004 02:29 PM
Script Problem - Does not give expected results Jose Muņiz Linux - General 3 07-12-2003 11:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration