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 / unix / Perguntas / 752446
Accepted
code userit
code userit
Asked: 2023-07-26 17:36:31 +0800 CST2023-07-26 17:36:31 +0800 CST 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

  • 772

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 2 respostas
  • 23 Views

2 respostas

  • Voted
  1. Best Answer
    pLumo
    2023-07-26T18:03:48+08:002023-07-26T18:03:48+08:00

    Com GNU sed:

    sed -z 's/\nBLENDEDCOST//g'
    

    ou perl:

    perl -0777pe 's/\nBLENDEDCOST//g'
    

    Para corresponder à sua saída, você precisará adicionar "Custo combinado" ao cabeçalho e remover a segunda linha e remover o USD, por exemplo, saída do tubo para:

    sed '1s/$/\BLENDEDCOST/; 2d; s/[[:blank:]]\+USD$//'
    

    No total:

    some_command | perl -0777pe 's/\nBLENDEDCOST//g;' | sed '1s/$/\tBLENDEDCOST/; 2d; s/[[:blank:]]\+USD$//'
    

    Saída:

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

    Alternativa muito fácil com saída que deve ser bastante fácil de corrigir:

    paste - -
    
    • 0
  2. Stéphane Chazelas
    2023-07-26T19:49:54+08:002023-07-26T19:49:54+08:00

    Com pcregrep:

    pcregrep -M -o1 -o2 '^KEYS\h+(.*)\nBLENDEDCOST(\h.*)' your-file
    

    Ou com padrão sed:

    sed -n '
      /^KEYS/ {
        N
        s/^KEYS[[:blank:]]\{1,\}\(.*\)\nBLENDEDCOST\([[:blank:]]\)/\1\2/p
        t
        D
      }' your-file
    

    (não cuidando de duplicatas , pois não está claro em sua descrição como elas seriam).

    • 0

relate perguntas

  • O comando ip suporta curingas?

  • Qual é a interface recomendada para um utilitário que requer muitos parâmetros? [fechado]

  • Execute o aplicativo X remotamente, execute a GUI no host remoto [fechado]

  • Fazendo mysql CLI me pedir uma senha interativamente

  • Pub / sub de linha de comando sem um servidor?

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