The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to use a command in sed s/match/replacement AbhishekG Shell Programming and Scripting 1 06-10-2008 10:44 AM
separating entries by using cat command za_7565 Shell Programming and Scripting 7 01-29-2008 08:00 AM
Regarding volumes entries! painulyarun UNIX for Advanced & Expert Users 0 05-04-2007 05:14 PM
/etc/system entries BG_JrAdmin SUN Solaris 1 04-23-2006 11:09 PM
Count log Entries odogbolu98 Shell Programming and Scripting 5 04-08-2003 02:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-23-2008
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 137
sed command to match log entries

Hello,

I would like to write a sed comman dwith pattern matching .to match those record which have some character(userd id) present in it.

Example :
Logfile contents --

127.0.0.1 - - [30/Apr/2008:22:48:20 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 1866
127.0.0.1 - - [30/Apr/2008:22:48:44 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 1921
127.0.0.1 - - [30/Apr/2008:22:49:28 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 2145
127.0.0.1 - - [30/Apr/2008:22:49:39 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 2165
127.0.0.1 - - [30/Apr/2008:22:51:43 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 500 602
127.0.0.1 - jam [30/Apr/2008:22:53:02 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3228
127.0.0.1 - - [30/Apr/2008:22:53:54 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3228
127.0.0.1 - - [30/Apr/2008:22:54:58 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3234
127.0.0.1 - - [30/Apr/2008:22:55:26 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3234
127.0.0.1 - mpt [30/Apr/2008:22:56:19 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3234
127.0.0.1 - - [30/Apr/2008:22:57:04 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3229
127.0.0.1 - unix [30/Apr/2008:22:57:47 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3227
127.0.0.1 - forum [30/Apr/2008:22:58:14 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3218

---------
These are sample entries in a apache log file ..
I would like to write a sed command to out put those record which have id present in 3rd column .

Out put needed --

127.0.0.1 - jam [30/Apr/2008:22:53:02 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3228
127.0.0.1 - mpt [30/Apr/2008:22:56:19 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3234
127.0.0.1 - unix [30/Apr/2008:22:57:47 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3227
127.0.0.1 - forum [30/Apr/2008:22:58:14 +0530] "POST /cgi-bin/cgi-module-example.pl HTTP/1.1" 200 3218


------------------------------------

I tried some think like
sed -n /([0-9]\{3})\.\1\.\1 - .? [aA-zZ-0-9].*/p access_log

but i am getting syntax error
  #2 (permalink)  
Old 07-23-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
With awk:


Code:
awk '$3 != "-"' file

  #3 (permalink)  
Old 07-23-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
If you prefer sed you can do something like:


Code:
sed -n '/.*[0-9] - [a-z].*/p' file

  #4 (permalink)  
Old 07-23-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
This would also work:

Code:
cat file | grep -v "\- \-"

  #5 (permalink)  
Old 07-23-2008
BMDan BMDan is offline
Registered User
  
 

Join Date: Jul 2008
Location: BlackMesh Managed Hosting
Posts: 66
Since I happen to know the syntax of that file, I know you can get away with something even more simple:


Code:
grep -vF ' - [' file

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0