-1

I have files with the below format:

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

Expected output:

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

This can be achieve by doing a pivot elsewhere, but in a bash script what would be a good way of doing this?

noobtoPro
  • 59
  • 1
  • 8

1 Answers1

0

While the link from oliv is good here is a pure shell solution:

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##*/}"
done
printf "\n"
for v in "${vals[@]}"; do
  printf "$fmt" "$v"
done
printf "\n"
Gilbert
  • 3,740
  • 17
  • 19