![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
sed '/NisLdapServer/!d;s/.*Gateway (\(.*\))|.*/\1/' your_file Code:
sed '1,4d;s/.*Gateway (\(.*\))|.*/\1/' your_file |
|
#3
|
|||
|
|||
|
Thanks Lorcan.. Can ya explain me the code?
|
|
#4
|
|||
|
|||
|
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
|
|||
|
|||
|
Code:
awk '/NisLdapServer/ { print substr( $0, index($0, "(") + 1, index($0, ")") - ( index($0, "(") +1 ) ) }' filename
|
|
#6
|
|||
|
|||
|
Code:
awk '/NisLdapServer/{
n=split($NF,r ,"|")
print r[1]
}' file
|
|
#7
|
|||
|
|||
|
Thanks Guys Its working
|
|||
| Google The UNIX and Linux Forums |