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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh pattern matching ripat Shell Programming and Scripting 5 02-10-2008 01:44 PM
help need for pattern matching HIMANI UNIX for Dummies Questions & Answers 10 01-22-2008 04:30 AM
pattern matching mercuryshipzz Shell Programming and Scripting 4 01-14-2008 08:01 PM
pattern matching in an if-then lumix Shell Programming and Scripting 4 12-14-2007 01:25 PM
Pattern matching sed leemjesse Shell Programming and Scripting 3 03-23-2005 01:06 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-17-2006
Registered User
 

Join Date: Jul 2006
Posts: 2
Pattern Matching

How to print the words with matching pattern. GREP lists the lines matching given pattern. But I want those words that matches the pattern
Reply With Quote
Forum Sponsor
  #2  
Old 07-17-2006
Registered User
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 88
Please read the man page carefully. -o option is there

echo " this is grep test" | grep -o "test"
test

-o, --only-matching
Show only the part of a matching line that matches PATTERN.
Reply With Quote
  #3  
Old 07-17-2006
Registered User
 

Join Date: Jul 2006
Posts: 2
-o option in grep is not there. I am using MKS toolkit that executes Unix shell command in windows environment. Any other way?
Reply With Quote
  #4  
Old 07-17-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
but -o option is not available in grep under solaris

-o option is not a standard option to grep
Reply With Quote
  #5  
Old 07-17-2006
Registered User
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 88
I don't have access to solaris machine right now. If I can recall correctly there are 2 executables for grep in Solaris. Second one should be under /usr/xpg/bin or /usr/xpg4/bin/grep
If not then check to see if egrep is there in your system ( which egrep).

Last edited by vish_indian; 07-17-2006 at 04:44 AM.
Reply With Quote
  #6  
Old 07-17-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
both grep and egrep utilities both searches for the pattern with their own reserved differences in usage

man egrep
Quote:
The egrep (expression grep) utility searches files for a
pattern of characters and prints all lines that contain that
pattern.
the other version of grep is available under /usr/xpg4/bin/grep

and the non-availability of option -o is for both and not just for the /usr/bin/grep
Reply With Quote
  #7  
Old 07-17-2006
Registered User
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 88
You might have to use awk then.

awk '/pat/{print $x}' filename

where x is the field no. assuming pattern always occurs in the same field.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0