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 07-30-2009, 08:47 AM   #1
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Rep: Reputation: 15
Searching for somewhat regular expression


Hi,

I have the /proc/net/ip_conntrack file that looks like as following:

tcp 6 95 TIME_WAIT src=192.168.252.200 dst=190.68.213.193 sport=3914 dport=8080 packets=4 bytes=184 src=190.68.213.193 dst=10.128.255.10 sport=8080 dport=3914 packets=2 bytes=88 [ASSURED] use=1 mark=0


Of course there are more lines. What I am searching for is those lines that match "dst=190.68.213.193" and DOESN'T match "dport=8080" (of course without quotes).

How can I do that?

I've tried with no success using:

grep "dst=190.68.213.193.*dport=[^8080]" /proc/net/ip_conntrack

Please could you help me to write the regular expression?


Thanks in advance!
 
Old 07-30-2009, 08:58 AM   #2
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS7
Posts: 267

Rep: Reputation: 58
grep "dst=190\.68\.213\.193" /proc/net/ip_conntrack | grep -v "dport=8080"

Last edited by david1941; 07-30-2009 at 09:00 AM. Reason: insert target file
 
Old 07-30-2009, 09:07 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I suggest alwasy starting with the simplest expressions and testing them to be sure you know how they work.

For starters:
grep "190.68.213.193" will match your example IP, but it will ALSO match "190x68g213y193". This is because "." means "any character"

Try this:

Code:
grep "190\.68\.213\.193" filename | grep -v "8080"
First, find all lines containing the specified IP, then---from those lines---find the ones that do NOT contain "8080"
 
Old 07-30-2009, 11:38 AM   #4
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
I suggest alwasy starting with the simplest expressions and testing them to be sure you know how they work.

For starters:
grep "190.68.213.193" will match your example IP, but it will ALSO match "190x68g213y193". This is because "." means "any character"

Try this:

Code:
grep "190\.68\.213\.193" filename | grep -v "8080"
First, find all lines containing the specified IP, then---from those lines---find the ones that do NOT contain "8080"
Thanks I thought too using 2 grep but I wonder if there is way to avoid to use a pipe....
 
Old 07-30-2009, 01:42 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Not tested:

Code:
sed -n '/8080/!{/190\.68\.213\.193/p}' filename
 
Old 07-30-2009, 01:45 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by david1941 View Post
grep "dst=190\.68\.213\.193" /proc/net/ip_conntrack | grep -v "dport=8080"
Acknowledging that this was posted while I was polishing the cannonball on my post.....(I'm slow...)
 
  


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
Regular Expression 0.o Programming 3 06-09-2009 02:28 AM
Searching for regular expression in command line Jean Of mArc Programming 9 08-11-2008 08:01 PM
Regular Expression msvinaykumar Programming 2 08-14-2006 08:48 AM
Do we have regular expression in C++ ? indian Programming 4 03-06-2006 09:54 AM
Regular Expression Help WeNdeL Linux - General 1 08-14-2003 10:08 AM

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

All times are GMT -5. The time now is 12:06 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