首页 Linux基础Linux命令正文

Linux命令-printf命令

Jean Linux命令 2018-10-29 355 0 Linux命令
printf命令:
格式化打印
例子:                                                                                         
printf "%s\n" aa bb cc dd 格式化输出换行                                                      
printf "%s %s\n" aa bb cc dd 两个参数输出换行                                                 
%s 字符串                                                                                     
%f 浮点格式                                                                                   
%d,%i 十进制整数                                                                              
\n 换行                                                                                       
\t 制表符                                                                                     
\r 回车                                                                                       
awk -F ":" 'BEGIN{printf "%-10s\t%s\n","用户名","ID"}{printf "%-10s\t%s\n",$1,$3}' /etc/passwd
-代表左对齐,默认是右对齐                                                                     
10代表当前替换的字符输出宽度,如果不够10字符,就以空格代替                                    
+ 是当替换的内容是数字是,输出的时候数字前面显示+号

评论