linux命令之格式化输出printf

1、printf:格式化输出命令

%ns:输出字符串。n是数字指代输出几个字符
%ni:输出整数。n是数字指代输出几个数字
%m.nf:输出浮点数。m和n是数字,指代输出的整数位数和小数位数。如%8.2f 代表共输出8位数,其中2位是小数,6位是整数。
输出格式:
\a:输出警告声音
\b:输出退格键,也就是Backspace键
\f:清除屏幕
\n:换行
\r:回车,也就是Enter键
\t:水平输出退格键,也就是Tab键
\v:垂直输出退格键,也就是Tab键
[root@localhost tmp]# printf '%s %s %s\n' 1 2 3 4 5 6
1 2 3
4 5 6
[root@localhost tmp]# cat student.txt ID Name gender mark 1 sl M 89 2 hus M 90 3 sd M 99

[root@localhost tmp]# printf '%s\t %s\t %s\t %s\n' $(cat student.txt)
ID Name gender mark
1 sl M 89
2 hus M 90
3 sd M 99
posted @ 2019-07-09 08:18  雷雨客  阅读(635)  评论(0编辑  收藏  举报