bash - awk/sed extract string from between patterns -
bash - awk/sed extract string from between patterns -
i know there has been few hundred forms of question asked on stackoverflow, can't seem find suitable reply question.
i'm trying parse through /etc/ldap.conf file on linux box can pick out description fields between (description= , ):
*-bash-3.2$ grep '^nss_base_passwd' /etc/ldap.conf nss_base_passwd ou=people,dc=ca,dc=somecompany,dc=com?one?|(description=td_fi)(description=td_f6)(description=td_f6)(description=tri_142)(description=14_142)(description=rex5)(description=rex5)(description=1950)*
i'm looking extract these own list no duplicates:
td_fi td_f6 tri_142 14_142 rex5 1950 (or on 1 line proper delimiter)
i had played sed few hours couldn't work - i'm not exclusively sure how utilize global option.
you utilize grep -p option,
$ grep '^nss_base_passwd' /etc/ldap.conf | grep -op '(?<=description\=)[^)]*' | uniq td_fi td_f6 tri_142 14_142 rex5 1950 explanation:
a positive lookbehind used in grep print characters after description= upto next ) bracket. uniq command used remove duplicates.
bash awk sed grep pattern-matching
Comments
Post a Comment