The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk: need to extract a line before a pattern npn35 Shell Programming and Scripting 17 06-29-2008 07:38 PM
extract a particular start and end pattern from a line manish205 Shell Programming and Scripting 7 02-07-2008 03:18 AM
Extract Pattern Sequence jaganadh Shell Programming and Scripting 5 12-10-2007 08:06 AM
Extract if pattern matches Raynon Shell Programming and Scripting 20 10-29-2007 01:44 AM
Please help! Sed extract a pattern zhen Shell Programming and Scripting 11 09-18-2006 09:36 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-07-2007
Registered User
 

Join Date: Jun 2007
Posts: 80
Extract the Pattern

Hello All,
can anyone help me out in extracting the pattern from a file...

The Input file is:

NFS B.11.11 ONC/NFS; Network-FileSystem,InformationServices,Utilities|123
NParProvider B.11.11.01.04.01.01 nPartition Provider|456
NPartition A.01.02 Enhanced NPartition Commands/789
Networking B.11.11 HP-UX_Lanlink_Product|1111
NisLdapServer B.04.00.02 The NIS/LDAP Gateway (ypldapd)|2222


I need to extract the pattern ypldapd from the fifth line which is enclosed between the brackets.. I need a script in ksh


Thanks in Advance
Reply With Quote
Forum Sponsor
  #2  
Old 08-07-2007
Registered User
 

Join Date: May 2007
Posts: 211
Code:
sed '/NisLdapServer/!d;s/.*Gateway (\(.*\))|.*/\1/' your_file
or

Code:
sed '1,4d;s/.*Gateway (\(.*\))|.*/\1/' your_file
Reply With Quote
  #3  
Old 08-07-2007
Registered User
 

Join Date: Jun 2007
Posts: 80
Thanks Lorcan.. Can ya explain me the code?
Reply With Quote
  #4  
Old 08-07-2007
Registered User
 

Join Date: May 2007
Posts: 211
The first part of the sed statement is to extract the line containing the pattern, So 1,4d or '/NisLdapServer/!d will delete all the lines except for the 5th line and then the second part i am extracting the pattern inbetween the braces
Reply With Quote
  #5  
Old 08-08-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Code:
awk '/NisLdapServer/ { print substr( $0, index($0, "(") + 1, index($0, ")") - ( index($0, "(") +1 ) ) }' filename
Reply With Quote
  #6  
Old 08-08-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
awk '/NisLdapServer/{
	n=split($NF,r ,"|")
	print r[1]
}' file
Reply With Quote
  #7  
Old 08-08-2007
Registered User
 

Join Date: Jun 2007
Posts: 80
Thanks Guys Its working
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:43 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