extract names from LDAP long names
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one:
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
I want to extract just the cn
names :
jsmith
bjones
how can I do it?
sed
New contributor
add a comment |Â
up vote
3
down vote
favorite
I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one:
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
I want to extract just the cn
names :
jsmith
bjones
how can I do it?
sed
New contributor
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one:
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
I want to extract just the cn
names :
jsmith
bjones
how can I do it?
sed
New contributor
I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one:
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
I want to extract just the cn
names :
jsmith
bjones
how can I do it?
sed
sed
New contributor
New contributor
edited 46 mins ago
msp9011
3,61543862
3,61543862
New contributor
asked 1 hour ago
Cadice
183
183
New contributor
New contributor
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
can be done with sed
:
sed 's/^.*cn=([^,]*).*$/1/' file
jsmith
bjones
or grep
grep -oP '(?<=cn=)[^, ]+' file
or perl
perl -lne '/cn=(w*),/ && print $1' file
or cut
& tr
cut -d'=' -f2 file | tr -d 'ou,'
add a comment |Â
up vote
2
down vote
using sed
:
sed -e 's/.*cn=(.*),ou.*/1/' file
using awk
awk -F '[=,]' 'print $2' file
or
awk -F 'cn=|,' 'print $2' file
add a comment |Â
up vote
2
down vote
% < input
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
% perl -nle 'print $1 if m/ cn=([^,]+)/' input
jsmith
bjones
on the assumptions that a comma will not appear in the record name and that cn=
do not appear elsewhere in the log
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
can be done with sed
:
sed 's/^.*cn=([^,]*).*$/1/' file
jsmith
bjones
or grep
grep -oP '(?<=cn=)[^, ]+' file
or perl
perl -lne '/cn=(w*),/ && print $1' file
or cut
& tr
cut -d'=' -f2 file | tr -d 'ou,'
add a comment |Â
up vote
2
down vote
accepted
can be done with sed
:
sed 's/^.*cn=([^,]*).*$/1/' file
jsmith
bjones
or grep
grep -oP '(?<=cn=)[^, ]+' file
or perl
perl -lne '/cn=(w*),/ && print $1' file
or cut
& tr
cut -d'=' -f2 file | tr -d 'ou,'
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
can be done with sed
:
sed 's/^.*cn=([^,]*).*$/1/' file
jsmith
bjones
or grep
grep -oP '(?<=cn=)[^, ]+' file
or perl
perl -lne '/cn=(w*),/ && print $1' file
or cut
& tr
cut -d'=' -f2 file | tr -d 'ou,'
can be done with sed
:
sed 's/^.*cn=([^,]*).*$/1/' file
jsmith
bjones
or grep
grep -oP '(?<=cn=)[^, ]+' file
or perl
perl -lne '/cn=(w*),/ && print $1' file
or cut
& tr
cut -d'=' -f2 file | tr -d 'ou,'
edited 48 mins ago
answered 1 hour ago
Goro
7,92653776
7,92653776
add a comment |Â
add a comment |Â
up vote
2
down vote
using sed
:
sed -e 's/.*cn=(.*),ou.*/1/' file
using awk
awk -F '[=,]' 'print $2' file
or
awk -F 'cn=|,' 'print $2' file
add a comment |Â
up vote
2
down vote
using sed
:
sed -e 's/.*cn=(.*),ou.*/1/' file
using awk
awk -F '[=,]' 'print $2' file
or
awk -F 'cn=|,' 'print $2' file
add a comment |Â
up vote
2
down vote
up vote
2
down vote
using sed
:
sed -e 's/.*cn=(.*),ou.*/1/' file
using awk
awk -F '[=,]' 'print $2' file
or
awk -F 'cn=|,' 'print $2' file
using sed
:
sed -e 's/.*cn=(.*),ou.*/1/' file
using awk
awk -F '[=,]' 'print $2' file
or
awk -F 'cn=|,' 'print $2' file
answered 1 hour ago
msp9011
3,61543862
3,61543862
add a comment |Â
add a comment |Â
up vote
2
down vote
% < input
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
% perl -nle 'print $1 if m/ cn=([^,]+)/' input
jsmith
bjones
on the assumptions that a comma will not appear in the record name and that cn=
do not appear elsewhere in the log
add a comment |Â
up vote
2
down vote
% < input
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
% perl -nle 'print $1 if m/ cn=([^,]+)/' input
jsmith
bjones
on the assumptions that a comma will not appear in the record name and that cn=
do not appear elsewhere in the log
add a comment |Â
up vote
2
down vote
up vote
2
down vote
% < input
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
% perl -nle 'print $1 if m/ cn=([^,]+)/' input
jsmith
bjones
on the assumptions that a comma will not appear in the record name and that cn=
do not appear elsewhere in the log
% < input
2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
% perl -nle 'print $1 if m/ cn=([^,]+)/' input
jsmith
bjones
on the assumptions that a comma will not appear in the record name and that cn=
do not appear elsewhere in the log
answered 1 hour ago
thrig
23k12854
23k12854
add a comment |Â
add a comment |Â
Cadice is a new contributor. Be nice, and check out our Code of Conduct.
Cadice is a new contributor. Be nice, and check out our Code of Conduct.
Cadice is a new contributor. Be nice, and check out our Code of Conduct.
Cadice is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474337%2fextract-names-from-ldap-long-names%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password