Skip to content
\n

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|\n
\n

I have tried the following command and it gets close but I can't figure out how to flatten it properly

\n
\n

open new.ldif | lines | split column ':' | transpose --header-row --keep-all

\n
\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╰───┴─────────────────────────────────────────┴─────────────────────────┴────────────┴──────────╯\n
\n

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

\n
\n

open new.ldif | lines | split column ':' | transpose --header-row

\n
\n
╭───┬─────────────────────────────────┬─────────────────┬────────┬──╮\n│ # │               dn                │      mail       │ status │  │\n├───┼─────────────────────────────────┼─────────────────┼────────┼──┤\n│ 0 │  dc=com,dc=corp,ou=org,cn=user1 │  [email protected] │  A     │  │\n╰───┴─────────────────────────────────┴─────────────────┴────────┴──╯\n
\n

Also I don't know what that extra column is doing or how to get rid of it lol.

\n

I tried posting this to the discord in #questions but for some reason I couldn't so here I am :)

\n

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:

\n
r#'\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 }
","upvoteCount":2,"url":"https://github.com/nushell/nushell/discussions/14251#discussioncomment-11147106"}}}
Discussion options

You must be logged in to vote

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 }

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@miversen33
Comment options

@idoric
Comment options

@weirdan
Comment options

Answer selected by miversen33
Comment options

You must be logged in to vote
1 reply
@weirdan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants