Introduction to printf in the shell

a grammar
printf 'output type output format' output content
output type:
%ns: Output string. n is a number indicating how many characters to output.
%ni: Output integers. n is a number that refers to how many numbers to output.
%mn: Output floating point number. m and n are numbers, referring to the number of integer digits and decimals of the output
For example, %8.2 represents a total of 8 digits, of which 2 digits are decimals and 6 digits are integers.
Output format:


 
 
Two actual combat
[root@localhost ~]# printf %s 1 2 3 4 5 6
123456[root@localhost ~]# printf %s %s %s 1 2 3 4 5 6
%s%s123456[root@localhost ~]# printf '%s %s %s' 1 2 3 4 5 6
1 2 34 5 6[root@localhost ~]# printf '%s\t%s\t%s\n' 1 2 3 4 5 6
1 2 3
4 5 6
[root@localhost ~]# printf '%s' $(cat student.txt)
1furongF852fengjF603cangF70[root@localhost ~]#
[root@localhost ~]# printf '%s\t%s\t%s\t%s\n' $(cat student.txt)
1 furong F 85
2 fengj F 60
3 cang F 70

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326151432&siteId=291194637