AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / user-565274

code userit's questions

Martin Hope
code userit
Asked: 2023-09-29 22:53:51 +0800 CST

Converter csv de json em nova coluna

  • 6

Abaixo está meu código json

[
{
    "kind": "user",
    "version": "v2",
    "metadata": {
      "name": "person1"
    },
    "spec": {
      "roles": [
        "access",
        "auditor",
        "editor",
        "abc-access"
      ],
      "status": {
        "is_locked": false,
        "locked_time": "0001-01-01T00:00:00Z",
        "lock_expires": "0001-01-01T00:00:00Z",
        "recovery_attempt_lock_expires": "0001-01-01T00:00:00Z"
      },
      "expires": "0001-01-01T00:00:00Z",
      "created_by": {
        "time": "2023-06-07T08:50:58.559675944Z",
        "user": {
          "name": "person2"
        }
      }
    }
  },
  {
    "kind": "user",
    "version": "v2",
    "metadata": {
      "name": "person2"
    },
    "spec": {
      "roles": [
        "access",
        "auditor",
        "editor",
        "abc-access"
      ],
      "status": {
        "is_locked": false,
        "locked_time": "0001-01-01T00:00:00Z",
        "lock_expires": "0001-01-01T00:00:00Z",
        "recovery_attempt_lock_expires": "0001-01-01T00:00:00Z"
      },
      "expires": "0001-01-01T00:00:00Z",
      "created_by": {
        "time": "2023-06-06T14:01:15.256905162Z",
        "user": {
          "name": "person5"
        }
      }
    }
  },
  {
    "kind": "user",
    "version": "v2",
    "metadata": {
      "name": "person3"
    },
    "spec": {
      "roles": [
        "access",
        "auditor",
        "editor",
        "abc-access"
      ],
      "status": {
        "is_locked": false,
        "locked_time": "0001-01-01T00:00:00Z",
        "lock_expires": "0001-01-01T00:00:00Z",
        "recovery_attempt_lock_expires": "0001-01-01T00:00:00Z"
      },
      "expires": "0001-01-01T00:00:00Z",
      "created_by": {
        "time": "2023-06-15T12:16:09.35013254Z",
        "user": {
          "name": "person2"
        }
      }
    }
  },
  {
    "kind": "user",
    "version": "v2",
    "metadata": {
      "name": "person3"
    },
    "spec": {
      "roles": [
        "access",
        "auditor",
        "editor",
        "abc-access"
      ],
      "status": {
        "is_locked": false,
        "locked_time": "0001-01-01T00:00:00Z",
        "lock_expires": "0001-01-01T00:00:00Z",
        "recovery_attempt_lock_expires": "0001-01-01T00:00:00Z"
      },
      "expires": "0001-01-01T00:00:00Z",
      "created_by": {
        "time": "2023-06-06T13:45:30.543520308Z",
        "user": {
          "name": "person6"
        }
      }
    }
  },
  {
    "kind": "user",
    "version": "v2",
    "metadata": {
      "name": "person4"
    },
    "spec": {
      "roles": [
        "access",
        "auditor",
        "editor",
        "abc-access"
      ],
      "status": {
        "is_locked": false,
        "locked_time": "0001-01-01T00:00:00Z",
        "lock_expires": "0001-01-01T00:00:00Z",
        "recovery_attempt_lock_expires": "0001-01-01T00:00:00Z"
      },
      "expires": "0001-01-01T00:00:00Z",
      "created_by": {
        "time": "2023-06-07T04:49:41.39245724Z",
        "user": {
          "name": "person5"
        }
      }
    }
  },
  {
    "kind": "user",
    "version": "v2",
    "metadata": {
      "name": "person5"
    },
    "spec": {
      "roles": [
        "access",
        "auditor",
        "editor",
        "abc-access"
      ],
      "traits": {
        "aws_role_arns": null,
        "db_names": null,
        "db_users": null,
        "kubernetes_groups": null,
        "kubernetes_users": null,
        "logins": [
          "ec2-user",
          "root"
        ],
        "windows_logins": null
      },
      "status": {
        "is_locked": false,
        "locked_time": "0001-01-01T00:00:00Z",
        "lock_expires": "0001-01-01T00:00:00Z",
        "recovery_attempt_lock_expires": "0001-01-01T00:00:00Z"
      },
      "expires": "0001-01-01T00:00:00Z",
      "created_by": {
        "time": "2023-06-06T13:51:39.173360152Z",
        "user": {
          "name": "person6"
        }
      }
    }
  },
  {
    "kind": "user",
    "version": "v2",
    "metadata": {
      "name": "person6"
    },
    "spec": {
      "roles": [
        "access",
        "editor",
        "auditor"
      ],
      "traits": {
        "aws_role_arns": null,
        "azure_identities": null,
        "db_names": null,
        "db_roles": null,
        "db_users": null,
        "gcp_service_accounts": null,
        "kubernetes_groups": null,
        "kubernetes_users": null,
        "logins": [
          "root",
          "ubuntu",
          "ec2-user"
        ],
        "windows_logins": null
      },
      "status": {
        "is_locked": false,
        "locked_time": "0001-01-01T00:00:00Z",
        "lock_expires": "0001-01-01T00:00:00Z",
        "recovery_attempt_lock_expires": "0001-01-01T00:00:00Z"
      },
      "expires": "0001-01-01T00:00:00Z",
      "created_by": {
        "time": "2023-06-06T13:41:41.579010534Z",
        "user": {
          "name": "xyz"
        }
      }
    }
  }
]

Estou convertendo para csv com

jq -r '.[] | [ .metadata.name ] ,  [ .spec.roles[] ] | @csv' ind.json

A saída do comando acima é como abaixo

"person1"
"alpha","gamma","beta","abc-access"
"person2"
"alpha","gamma","beta","abc-access"
"person3"
"alpha","gamma","beta","abc-access"
"person3"
"alpha","gamma","beta","abc-access"
"person4"
"alpha","gamma","beta","abc-access"
"person5"
"alpha","gamma","beta","abc-access"
"person6"
"alpha","gamma","beta","auditor"

Quero o nome e as funções em colunas diferentes. Quero o nome e as funções na mesma linha com espaço suficiente para que se copiarmos o paster no excel, serão duas colunas, uma com "nome" e outra com "função". Também estou procurando opções se obtivermos saída sem aspas duplas

Abaixo está o resultado esperado

person1    alpha,gamma,beta,abc-access
person2    alpha,gamma,beta,abc-access
person3    alpha,gamma,beta,abc-access
person3    alpha,gamma,beta,abc-access
person4    alpha,gamma,beta,abc-access
person5    alpha,gamma,beta,abc-access
person6    alpha,gamma,beta,auditor
json
  • 1 respostas
  • 28 Views
Martin Hope
code userit
Asked: 2023-09-22 17:54:41 +0800 CST

Não é possível passar comandos AWS CLI entre aspas duplas na sintaxe json

  • 5

Estou trabalhando com o script abaixo, recebendo um erro de sintaxe porque não foi possível buscar credenciais do gerenciador de segredos. "username":"Comando AWS CLI de chave de acesso que inseri", "password":"Comando AWS CLI de chave secreta que inseri". Ótimo se alguém puder ajudar

#!/bin/bash

# Send the POST request and capture the response
response=$(curl -k \
-H "Content-Type: application/json" \
-X POST \
-d \
'{
"username":"'aws secretsmanager get-secret-value --region ap-south-1 --secret-id poc | jq --raw-output '.SecretString' | jq -r '.Access_Key''",
"password":"'aws secretsmanager get-secret-value --region ap-south-1 --secret-id poc | jq --raw-output '.SecretString' | jq -r '.Secret_Key''"
}' \
https://<region>/api/v1/authenticate)
bash
  • 2 respostas
  • 37 Views
Martin Hope
code userit
Asked: 2023-07-26 17:36:31 +0800 CST

Existe a opção de converter as saídas da linha em uma nova coluna no Linux e excluir a entrada duplicada na linha

  • 5

Eu tenho uma saída cli como abaixo,

GROUP DEFINITIONS   SERVICE DIMENSION
RESULTSBYTIME   False
KEYS    AWS CloudShell
BLENDEDCOST 0.0000026589    USD
KEYS    AWS CloudTrail
BLENDEDCOST 0.000001    USD
KEYS    AWS Config
BLENDEDCOST 46.921  USD
KEYS    AWS Glue
BLENDEDCOST 355.70735552    USD
KEYS    AWS Key Management Service
BLENDEDCOST 0.10418545  USD
KEYS    AWS Lambda
BLENDEDCOST 0.0000002605    USD
KEYS    AWS Migration Hub Refactor Spaces
BLENDEDCOST 0   USD
KEYS    AWS Secrets Manager
BLENDEDCOST 2.0496788951    USD
KEYS    AWS Security Hub
BLENDEDCOST 0.028892556 USD
KEYS    AWS Service Catalog
BLENDEDCOST 0   USD
KEYS    AWS Step Functions
BLENDEDCOST 0.0000000031    USD
KEYS    AWS Support (Business)
BLENDEDCOST 246.2376324993  USD
KEYS    AWS Systems Manager
BLENDEDCOST 0.000351    USD
KEYS    AWS Transfer Family
BLENDEDCOST 208.8   USD
KEYS    Amazon EC2 Container Registry (ECR)
BLENDEDCOST 0.2636971622    USD
KEYS    EC2 - Other
BLENDEDCOST 325.4630384796  USD
KEYS    Amazon Elastic Compute Cloud - Compute
BLENDEDCOST 694.4962624953  USD
KEYS    Amazon Elastic Container Service for Kubernetes
BLENDEDCOST 69.890509083    USD
KEYS    Amazon Elastic File System
BLENDEDCOST 0.0000002652    USD
KEYS    Amazon Elastic Load Balancing
BLENDEDCOST 73.2040001769   USD

Estou esperando a saída abaixo, a duplicata BLENDEDCOST deve ser removida e as CHAVES devem vir em uma nova linha. Converter linha em colunas e duplicar deve ser removido?

AWS CloudShell  0.0000026589    USD
AWS CloudTrail  0.000001    USD
AWS Config  46.921  USD
AWS Glue    355.7073555 USD
AWS Key Management Service  0.10418545  USD
AWS Lambda  0.0000002605    USD
AWS Migration Hub Refactor Spaces   0   USD
AWS Secrets Manager 2.049678895 USD
AWS Security Hub    0.028892556 USD
AWS Service Catalog 0   USD
AWS Step Functions  0.0000000031    USD
AWS Support (Business)  246.2376325 USD
AWS Systems Manager 0.000351    USD
AWS Transfer Family 208.8   USD
Amazon EC2 Container Registry (ECR) 0.2636971622    USD
EC2 - Other 325.4630385 USD
Amazon Elastic Compute Cloud - Compute  694.4962625 USD
Amazon Elastic Container Service for Kubernetes 69.89050908 USD
Amazon Elastic File System  0.0000002652    USD
Amazon Elastic Load Balancing   73.20400018 USD
Amazon Elastic MapReduce    2.28898852  USD
Amazon Glacier  0.0000000025    USD
Amazon GuardDuty    7.367077065 USD
Amazon Inspector    1   USD
Amazon Location Service 0   USD
Amazon Relational Database Service  388.1651428 USD
Amazon Route 53 0.508976    USD
Amazon Simple Notification Service  0.2022960904    USD
Amazon Simple Queue Service 0   USD
Amazon Simple Storage Service   3.338266835 USD
Amazon Simple Workflow Service  0.0000000015    USD
Amazon Virtual Private Cloud    147.4110373 USD
AmazonCloudWatch    60.12971039 USD
CloudWatch Events   0.000048    USD
CodeBuild   29.71339194 USD
command-line
  • 2 respostas
  • 23 Views

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Possível firmware ausente /lib/firmware/i915/* para o módulo i915

    • 3 respostas
  • Marko Smith

    Falha ao buscar o repositório de backports jessie

    • 4 respostas
  • Marko Smith

    Como exportar uma chave privada GPG e uma chave pública para um arquivo

    • 4 respostas
  • Marko Smith

    Como podemos executar um comando armazenado em uma variável?

    • 5 respostas
  • Marko Smith

    Como configurar o systemd-resolved e o systemd-networkd para usar o servidor DNS local para resolver domínios locais e o servidor DNS remoto para domínios remotos?

    • 3 respostas
  • Marko Smith

    apt-get update error no Kali Linux após a atualização do dist [duplicado]

    • 2 respostas
  • Marko Smith

    Como ver as últimas linhas x do log de serviço systemctl

    • 5 respostas
  • Marko Smith

    Nano - pule para o final do arquivo

    • 8 respostas
  • Marko Smith

    erro grub: você precisa carregar o kernel primeiro

    • 4 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Martin Hope
    user12345 Falha ao buscar o repositório de backports jessie 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl Por que a maioria dos exemplos do systemd contém WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky Como exportar uma chave privada GPG e uma chave pública para um arquivo 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll status systemctl mostra: "Estado: degradado" 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim Como podemos executar um comando armazenado em uma variável? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S Por que /dev/null é um arquivo? Por que sua função não é implementada como um programa simples? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 Como ver as últimas linhas x do log de serviço systemctl 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - pule para o final do arquivo 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla Por que verdadeiro e falso são tão grandes? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve