[bash] printf使用范例

#!/bin/sh

function get_file_size()
{
	line=${1:1:${#1}-2}
	fname=${line%%:*}	# 取':'之前的部分
	size=${line#* }		# 取' '之后的部分
}

function getRuntime()
{
	line=${1#*=}
	rtime=${line//[^0-9.]/}
}

dos2unix log.log > /dev/null 2>&1

printf "序号\t\t录像文件\t大小(KB)\tRead1(ms)\tRead2(ms)\n"
echo "-----------------------------------------------------------------------------"
i=1
while read line
do
	if [ ${#line} -gt 0 ] && [ ${line:0:1} = "[" ]; then
		get_file_size "$line"
		read line
		read line
		getRuntime "$line"
		read1=$rtime
		read line
		read line
		getRuntime "$line"
		read2=$rtime
		
		printf "%3d\t%s\t%s\t\t%.2f\t\t%.2f\n" $i $fname $size $read1 $read2

		let i=i+1
	fi
done < log.log


禁止某些命令执行的输出,参考:dos2unix log.log > /dev/null 2>&1

你可能感兴趣的:([bash] printf使用范例)