aajan
August 8, 2007, 1:24am
1
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
lorcan
August 8, 2007, 1:29am
2
sed '/NisLdapServer/!d;s/.*Gateway (\(.*\))|.*/\1/' your_file
or
sed '1,4d;s/.*Gateway (\(.*\))|.*/\1/' your_file
aajan
August 8, 2007, 1:47am
3
Thanks Lorcan.. Can ya explain me the code?
lorcan
August 8, 2007, 1:50am
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
awk '/NisLdapServer/ { print substr( $0, index($0, "(") + 1, index($0, ")") - ( index($0, "(") +1 ) ) }' filename
awk '/NisLdapServer/{
n=split($NF,r ,"|")
print r[1]
}' file