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
ksh pattern matching ripat Shell Programming and Scripting 5 02-10-2008 04:44 PM
help need for pattern matching HIMANI UNIX for Dummies Questions & Answers 10 01-22-2008 07:30 AM
pattern matching mercuryshipzz Shell Programming and Scripting 4 01-14-2008 11:01 PM
pattern matching in an if-then lumix Shell Programming and Scripting 4 12-14-2007 04:25 PM
Pattern matching sed leemjesse Shell Programming and Scripting 3 03-23-2005 04:06 AM

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-17-2006
op4_u op4_u is offline
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
  #2 (permalink)  
Old 07-17-2006
vish_indian vish_indian is offline
Registered User
  
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 92
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.
  #3 (permalink)  
Old 07-17-2006
op4_u op4_u is offline
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?
  #4 (permalink)  
Old 07-17-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
but -o option is not available in grep under solaris

-o option is not a standard option to grep
  #5 (permalink)  
Old 07-17-2006
vish_indian vish_indian is offline
Registered User
  
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 92
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 08:44 AM..
  #6 (permalink)  
Old 07-17-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
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
  #7 (permalink)  
Old 07-17-2006
vish_indian vish_indian is offline
Registered User
  
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 92
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.
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 02:48 PM.


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