gpt4 book ai didi

linux - 格式化许多记录,使用公共(public)键将行转换为列

转载 作者:太空宇宙 更新时间:2023-11-04 05:13:16 25 4
gpt4 key购买 nike

我有以下格式的文件:

AS/2018100400 : 105
AS/2018100401 : 34
AS/2018100402 : 1
AS/2018100403 : 8
AS/2018100404 : 14
AS/2018100405 : 37
AS/2018100406 : 7
AS/2018100407 : 141
AS/2018100408 : 21
AS/2018100409 : 37
AS/2018100410 : 35
AS/2018100411 : 3
AS/2018100412 : 31
AS/2018100413 : 39
AS/2018100414 : 32
AS/2018100415 : 32
AS/2018100416 : 39
AS/2018100417 : 32
AS/2018100418 : 4
AS/2018100419 : 43
AS/2018100420 : 40
AS/2018100421 : 33
AS/2018100422 : 25
AS/2018100423 : 15

预期输出:

     2018100400 2018100401.....  2018100423
AS 105 34 ..... 15

这可以通过在其他地方进行数据透视来实现,但是在 bash 脚本中什么是执行此操作的好方法?

最佳答案

虽然来自 oliv 的链接很好,但这里是一个纯 shell 解决方案:

fmt='%10s 'declare -a vals;while read fname colon value; do    if [ "$colon" != ":" ]; then        echo "Improper line: $fname $colon $valjue";        continue;    fi      vals+=( "$value" );    printf "$fmt" "${fname##*/}"doneprintf "\n"for v in "${vals[@]}"; do  printf "$fmt" "$v"doneprintf "\n"

关于linux - 格式化许多记录,使用公共(public)键将行转换为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52702981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com