LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 11:47 AM   #1
dthims
Member
 
Registered: Mar 2003
Posts: 50

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, 12:03 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,784

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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, 12:16 PM   #3
dthims
Member
 
Registered: Mar 2003
Posts: 50

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

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
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



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 12:10 PM
LXer: id Software: Linux Hasn't Produced Positive Results LXer Syndicated Linux News 6 08-06-2012 11:54 AM
getent not returning expected results anirbanz Linux - Software 0 01-10-2006 08:44 PM
difference between distro produced by group vs. produced by single person lostsoul Linux - General 2 04-08-2004 01:29 PM
Script Problem - Does not give expected results Jose Muņiz Linux - General 3 07-12-2003 10:10 PM

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

All times are GMT -5. The time now is 07:59 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
Open Source Consulting | Domain Registration