LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-13-2009, 09:59 AM   #1
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Rep: Reputation: 15
Using grep that matches only just a word with no "-" at the end


Hi,

I hav a log files with a bunch of lines more or less as follows:

/var/log/radius/radiusd-inner-tunnel-peap-20090812.log:Wed Aug 12 11:30:31 2009 : Auth: Login OK: [pepe] (from client Sarlanga-PVIII-I-bis port 0 via TLS tunnel)

/var/log/radius/radiusd-inner-tunnel-peap-20090812.log:Wed Aug 12 11:30:32 2009 : Auth: Login OK: [pepe2] (from client Sarlanga-PVIII-I port 0 via TLS tunnel)

I'd want to get only those lines that has Sarlanga-PVIII-I but *not* Sarlanga-PVIII-I-bis


If I use '-w' grep flag is not useful because it considers "-" as part of the word. How can I prevent it?

Thanks in advance!!
 
Old 08-13-2009, 10:07 AM   #2
sebelk
Member
 
Registered: Jan 2007
Posts: 66

Original Poster
Rep: Reputation: 15
Please bear in mind that use something as grep -w Sarlanga-PVIII-I| grep "I-bis" is not what I am looking for because I am using really in a for loop, something like:

for i in SS PB I I-bis II III IV V VI VII VIII IX
do echo -e PVIII-$i="$(grep OK /var/log/radius/radiusd-*-$(date -d 'yesterday' +%Y%m%d).log | grep -w PVIII-$i[A-Za-z]* | egrep -v 'anonymous | awk '{print $10}' | sort -fu | wc -l)\n"
done

So I am evaluating in turn PVIII-I and PVIII-bis

Thanks in advance
 
Old 08-13-2009, 10:10 AM   #3
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by sebelk View Post
Hi,

I hav a log files with a bunch of lines more or less as follows:

/var/log/radius/radiusd-inner-tunnel-peap-20090812.log:Wed Aug 12 11:30:31 2009 : Auth: Login OK: [pepe] (from client Sarlanga-PVIII-I-bis port 0 via TLS tunnel)

/var/log/radius/radiusd-inner-tunnel-peap-20090812.log:Wed Aug 12 11:30:32 2009 : Auth: Login OK: [pepe2] (from client Sarlanga-PVIII-I port 0 via TLS tunnel)

I'd want to get only those lines that has Sarlanga-PVIII-I but *not* Sarlanga-PVIII-I-bis


If I use '-w' grep flag is not useful because it considers "-" as part of the word. How can I prevent it?

Thanks in advance!!


Code:
grep 'Sarlanga-PVIII-I ' var/log/radius/radiusd-inner-tunnel-peap-20090812.log
 
Old 08-13-2009, 01:02 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Slightly more robust is:

Code:
grep '<pattern>[[:blank]]' filename
Even this fails if <pattern> is followed by a newline

Brute force:

Code:
grep '<goodpattern>' filename | grep -v '<badpattern>'
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
fdisk reports odd "Start "and "End" sectors on single partition eponymous Linux - Software 3 10-01-2007 03:41 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM

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

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