printf--Format and print date formatted output data with printf options
Reference: http://www.computerhope.com/unix/uprintf.htm
Basic English Learning
Binary: Binanry number
Octal: otcal number
Decimal: Decimal number
Hex: Hexadecimal number
1 Basic printout (default non-line break \ n NewLine)
[[email protected] gold]# printf "Hello,world"
Hello,world[[email protected] gold]#
[[email protected] gold] #printf "hello,world\n"
Hello,world
Conversion of 2 binary
%x Hex
%d decimal
%o Octal
Decimal Turn 16 binary
[[email protected] gold]# printf "%x\n" 27
1b
16 Binary to Decimal
[[email protected] gold]# printf "%d\n" 0x1b
27
(Note that the conversion can be made using the BC command, such as 2 binary) ibase input, obase output of the binary)
10 Binary to 2 binary
[Email protected] gold]# echo ' obase=2;10 ' |BC
1010
Handling with variables is commonly used in shell scripts
[Email protected] tmp]# a=10
[Email protected] tmp]# echo "obase=2; $a" |BC
1010
2 Binary Conversion 10 binary
[Email protected] gold]# echo ' ibase=2;111 ' |BC
7
Advanced usage in general:
[email protected] tmp]# cat file.txt 100200300
[[email protected] tmp]# awk ' {print ' ibase=10;obase=2; ' $ ' file.txt |bc |xargs printf '%08d\n ' 011001001100100010010110 0
3 Formatting output alignment (Chinese and English mixed effect is not obvious)
Syntax: %flags width.precision format-specifier
-Is flag left justified by default right justified
12 is width indicates the length of the character occupies extra space, the length of the string is not enough to display.
. precision represents the decimal place of a floating-point number
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8C/9C/wKiom1hxvv_CrtPqAAATyPjtbYk958.png "title=" Print1.png "alt=" Wkiom1hxvv_crtpqaaatypjtbyk958.png "/>
This article is from "Swallow Lie triple" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1890139
Summarize the usage of the printf command under Linux