在 UNIX 中重新排列文件内容

在 UNIX 中重新排列文件内容

我需要重新安排一下:

 ----------------------------------------------------------------
 - Partition Name: testblade012                                 -
 - Type: Shared-SMT-4                                           -
 - Entitled Capacity: 0.30                                      -
 ----------------------------------------------------------------

进入这个:

 ----------------------------------------------------------------
 - Partition Name                           : testblade012      -
 - Type                                     : Shared-SMT-4      -
 - Entitled Capacity                        : 0.30              -  
 ----------------------------------------------------------------

答案1

只是printf

while IFS=[:] read f1 f2
do
    [ "$f2" ] && printf '%-40s: %-22s-\n' "$f1" "$(echo ${f2%-})" || echo "$f1"
done <<<' ----------------------------------------------------------------
 - Partition Name: testblade012                                 -
 - Type: Shared-SMT-4                                           -
 - Entitled Capacity: 0.30                                      -
 ----------------------------------------------------------------'

或者与awk

awk -F'[:]' '$2{sub(" *-$","",$2);$0=sprintf("%-40s:%-23s-",$1,$2)}1'

相关内容