내 CLI 출력은 다음과 같습니다.
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
출력은 다음과 같을 것으로 예상합니다. BLENDEDCOST 중복 항목을 제거하고 KEYS가 새 줄에 나타나야 합니다. 행을 열로 변환하고 중복 항목을 제거하시겠습니까?
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
답변1
GNU 사용 sed
:
sed -z 's/\nBLENDEDCOST//g'
또는 perl
:
perl -0777pe 's/\nBLENDEDCOST//g'
출력을 일치시키려면 헤더에 "혼합 비용"을 추가하고 두 번째 줄을 제거한 후 USD
출력을 다음으로 파이프해야 합니다.
sed '1s/$/\BLENDEDCOST/; 2d; s/[[:blank:]]\+USD$//'
총:
some_command | perl -0777pe 's/\nBLENDEDCOST//g;' | sed '1s/$/\tBLENDEDCOST/; 2d; s/[[:blank:]]\+USD$//'
산출:
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
출력을 수정하기 매우 쉬운 매우 간단한 대안:
paste - -
답변2
그리고 pcregrep
:
pcregrep -M -o1 -o2 '^KEYS\h+(.*)\nBLENDEDCOST(\h.*)' your-file
또는 표준을 사용하십시오 sed
.
sed -n '
/^KEYS/ {
N
s/^KEYS[[:blank:]]\{1,\}\(.*\)\nBLENDEDCOST\([[:blank:]]\)/\1\2/p
t
D
}' your-file
(돌보지 않고중복귀하의 설명에서 그것이 어떻게 보일지 명확하지 않기 때문입니다.)