Currently I am just trying to get this into a table (like this)
\n|#|dn|mail|status|\n|-|-|-|\n|0|dc=com,dc=corp,ou=org,cn=user1|[email protected]|A|\n|1|dc=com,dc=corp,ou=org,cn=user2|[email protected]|A|\n|2|dc=com,dc=corp,ou=org,cn=user3|[email protected]|I|\nI have tried the following command and it gets close but I can't figure out how to flatten it properly
\n\n\nopen new.ldif | lines | split column ':' | transpose --header-row --keep-all
\n
╭───┬─────────────────────────────────────────┬─────────────────────────┬────────────┬──────────╮\n│ # │ dn │ mail │ status │ │\n├───┼─────────────────────────────────────────┼─────────────────────────┼────────────┼──────────┤\n│ 0 │ ╭───┬─────────────────────────────────╮ │ ╭───┬─────────────────╮ │ ╭───┬────╮ │ ╭───┬──╮ │\n│ │ │ 0 │ dc=com,dc=corp,ou=org,cn=user1 │ │ │ 0 │ [email protected] │ │ │ 0 │ A │ │ │ 0 │ │ │\n│ │ │ 1 │ dc=com,dc=corp,ou=org,cn=user2 │ │ │ 1 │ [email protected] │ │ │ 1 │ A │ │ │ 1 │ │ │\n│ │ │ 2 │ dc=com,dc=corp,ou=org,cn=user1 │ │ │ 2 │ [email protected] │ │ │ 2 │ I │ │ ╰───┴──╯ │\n│ │ ╰───┴─────────────────────────────────╯ │ ╰───┴─────────────────╯ │ ╰───┴────╯ │ │\n╰───┴─────────────────────────────────────────┴─────────────────────────┴────────────┴──────────╯\nI can flatten them with some each fuckery but it doesn't retain the relations. What am I missing? If I forgo --keep-all, I get exactly what I want but only for the first (or last) record
\n\n\nopen new.ldif | lines | split column ':' | transpose --header-row
\n
╭───┬─────────────────────────────────┬─────────────────┬────────┬──╮\n│ # │ dn │ mail │ status │ │\n├───┼─────────────────────────────────┼─────────────────┼────────┼──┤\n│ 0 │ dc=com,dc=corp,ou=org,cn=user1 │ [email protected] │ A │ │\n╰───┴─────────────────────────────────┴─────────────────┴────────┴──╯\nAlso I don't know what that extra column is doing or how to get rid of it lol.
\nI tried posting this to the discord in #questions but for some reason I couldn't so here I am :)
What am I missing?
","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"If records are guaranteed to be separated by empty lines I'd go with something like this:
\nr#'\ndn: dc=com,dc=corp,ou=org,cn=user1\nmail: [email protected]\nstatus: A\n\ndn: dc=com,dc=corp,ou=org,cn=user2\nmail: [email protected]\nstatus: A\n\ndn: dc=com,dc=corp,ou=org,cn=user3\nmail: [email protected]\nstatus: I\n'# \n| str trim \n| split row -r '\\n\\n' \n| each { lines | split column ':' | str trim | transpose --header-row | first }-
|
Based on the work explained in #13742 Hey! So I am a bit new to nushell. I have been exploring using nushell to work with ldifs that I am generating from active directory. Below is an example ldif that I am trying to convert into a table. Currently I am just trying to get this into a table (like this) I have tried the following command and it gets close but I can't figure out how to flatten it properly
I can flatten them with some each fuckery but it doesn't retain the relations. What am I missing? If I forgo --keep-all, I get exactly what I want but only for the first (or last) record
Also I don't know what that extra column is doing or how to get rid of it lol. I tried posting this to the discord in What am I missing? |
Beta Was this translation helpful? Give feedback.
-
|
If records are guaranteed to be separated by empty lines I'd go with something like this: r#'
dn: dc=com,dc=corp,ou=org,cn=user1
mail: [email protected]
status: A
dn: dc=com,dc=corp,ou=org,cn=user2
mail: [email protected]
status: A
dn: dc=com,dc=corp,ou=org,cn=user3
mail: [email protected]
status: I
'#
| str trim
| split row -r '\n\n'
| each { lines | split column ':' | str trim | transpose --header-row | first } |
Beta Was this translation helpful? Give feedback.
-
|
If you love regexes you could try something like this too. ❯ open f.ldif | collect | parse -r 'dn: (?<dn>.*\n)mail: (?<mail>.*\n)status: (?<status>.*\n)' | str trim
╭─#─┬───────────────dn───────────────┬──────mail──────┬─status─╮
│ 0 │ dc=com,dc=corp,ou=org,cn=user1 │ user1@corp.com │ A │
│ 1 │ dc=com,dc=corp,ou=org,cn=user2 │ user2@corp.com │ A │
│ 2 │ dc=com,dc=corp,ou=org,cn=user3 │ user3@corp.com │ I │
╰───┴────────────────────────────────┴────────────────┴────────╯ |
Beta Was this translation helpful? Give feedback.
If records are guaranteed to be separated by empty lines I'd go with something like this: