The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 10:38 PM
extract a particular start and end pattern from a line manish205 Shell Programming and Scripting 7 02-07-2008 06:18 AM
Extract Pattern Sequence jaganadh Shell Programming and Scripting 5 12-10-2007 11:06 AM
Extract if pattern matches Raynon Shell Programming and Scripting 20 10-29-2007 04:44 AM
Please help! Sed extract a pattern zhen Shell Programming and Scripting 11 09-18-2006 12:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-08-2007
aajan aajan is offline
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
  #2 (permalink)  
Old 08-08-2007
lorcan lorcan is offline
Registered User
  
 

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

Code:
sed '1,4d;s/.*Gateway (\(.*\))|.*/\1/' your_file
  #3 (permalink)  
Old 08-08-2007
aajan aajan is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 80
Thanks Lorcan.. Can ya explain me the code?
  #4 (permalink)  
Old 08-08-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
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
  #5 (permalink)  
Old 08-08-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Code:
awk '/NisLdapServer/ { print substr( $0, index($0, "(") + 1, index($0, ")") - ( index($0, "(") +1 ) ) }' filename
  #6 (permalink)  
Old 08-08-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Code:
awk '/NisLdapServer/{
	n=split($NF,r ,"|")
	print r[1]
}' 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 04:16 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