LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-12-2022, 01:36 AM   #1
Alexmicu
LQ Newbie
 
Registered: Feb 2022
Posts: 15

Rep: Reputation: 0
grep filtering question


in /tmp folder, i have around 30 web server log files, i want to retrieve lines with status code 4** and srcip not belong to 127.0.0.1 and 192.168.*.*
I go to /tmp and write below query:
cat *.log | grep "status code:4**"| grep ^127.0.0.1 and ^192.168.*.*
but it said ^127.0.0.1 no such file.
any idea? do we need to use regex?
 
Old 03-12-2022, 02:03 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
what you posted is syntactically incorrect.
Code:
grep 'status code: 4..' *.log | grep -v 127.0.0.1 | grep -v '192.168.*.*'
probably works better. Would be nice to learn grep (if you wish to use it)
 
1 members found this post helpful.
Old 03-12-2022, 04:58 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Alexmicu View Post
in /tmp folder, i have around 30 web server log files, i want to retrieve lines with status code 4** and srcip not belong to 127.0.0.1 and 192.168.*.*
I go to /tmp and write below query:
cat *.log | grep "status code:4**"| grep ^127.0.0.1 and ^192.168.*.*
but it said ^127.0.0.1 no such file.
any idea? do we need to use regex?
Try
Code:
grep 'status code:4..' *.log | grep -vE '^127.0.0.1|^192.168.*'
Though I'm not sure about the syntax - are you sure it's always exactly "status code:" immediately followed by the 4xx status code, no spaces? Are you sure the srcip is always the first thing on each line?
etc.
 
Old 03-12-2022, 08:49 PM   #4
Alexmicu
LQ Newbie
 
Registered: Feb 2022
Posts: 15

Original Poster
Rep: Reputation: 0
I want to filter out srcip=127.0.0.1 or 192.168.*.*
but we want dstip: 127.0.0.1 or 192.168.*.*
 
Old 03-13-2022, 03:09 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Alexmicu View Post
I want to filter out srcip=127.0.0.1 or 192.168.*.*
but we want dstip: 127.0.0.1 or 192.168.*.*
Sorry but this makes even less sense than your previous post
 
Old 03-13-2022, 04:04 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
Quote:
Originally Posted by ondoho View Post
Sorry but this makes even less sense than your previous post
I guess that would be something like source ip and destination ip. Probably that makes some sense.

Quote:
Originally Posted by Alexmicu View Post
any idea? do we need to use regex?
yes
 
Old 03-13-2022, 08:52 AM   #7
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by Alexmicu View Post
in /tmp folder, i have around 30 web server log files, i want to retrieve lines with status code 4** and srcip not belong to 127.0.0.1 and 192.168.*.*
Quote:
Originally Posted by Alexmicu View Post
I want to filter out srcip=127.0.0.1 or 192.168.*.*
but we want dstip: 127.0.0.1 or 192.168.*.*
Post a handful of example lines from those log files, and whether they should be kept/excluded.

(If necessary, replace sensitive information with dummy strings, but don't change the format/structure of the line.)

Also, use "[code]..[/code]" to preserve formatting.

 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
content filtering with layer7- filtering rose1366m Linux - Networking 1 05-04-2011 11:10 AM
Content Filtering - using grep hiteshthappa Linux - Newbie 2 07-15-2008 04:11 PM
Filtering Problem (using grep) gauge73 Linux - Newbie 4 12-16-2003 10:35 PM
Sendmail Spam filtering and Virus filtering MrJoshua Linux - General 2 04-03-2003 10:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:53 PM.

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