【发布时间】:2023-03-22 09:30:01
【问题描述】:
我有一个脚本循环遍历目录中的每个文本文件,并将内容存储在变量中。内容长度可以是 1-50 个字符。文本文件的数量未知。我想以这样一种方式打印内容,使每个变量都落入一个干净的列中。
for file in $LIBPATH/*.txt; do
name=$( awk 'FNR == 1 {print $0}' $file )
height=$( awk 'FNR == 2 {print $0}' $file )
weight=$( awk 'FNR == 3 {print $0}' $file )
echo $name $height $weight
done
此代码产生输出:
Avril Stewart 99 54
Sally Kinghorn 170 60
John Young 195 120
而期望的输出是:
Avril Stewart 99 54
Sally Kinghorn 170 60
John Young 195 120
谢谢!
【问题讨论】:
标签: arrays bash printf output indentation