In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Programmers who have used c language should be familiar with the printf command, which mimics the printf () function of c language.
The function of the printf command is to output text in the format we specify
We can see that the echo command normally outputs a text for line wrapping, while printf outputs text without line wrapping.
[root@zhaocheng ~] # echo beijingbeijing [root@zhaocheng ~] # printf beijingbeijing [root@zhaocheng ~] #
If you use printf for newline output, you can add\ n
[root@zhaocheng ~] # printf "beijing\ n" beijing
Printf is so troublesome, but why do people still use it all the time? its real function is the ability to format output text.
When printing, echo-e can use\ nline feeds for output, while printf can also add line feeds or "% s\ n" for output.
However, the ability of printf is obviously faster when dealing with multi-line wrapping text. When using\ nWhen dealing with 1000 more lines that need to be wrapped, it shows that echo-e\ nis inadequate, that is,% s is instead of the incoming parameter,% s replaces 123 ~ 456 in the command. When we use% s\ n, we will format the output to "abc\ n" through printf output, and so on.
[root@zhaocheng ~] # echo-e "123\ n456\ n789\ naaa\ nbbb\ nccc" 123456789aaabbbccc [root@zhaocheng ~] # printf "123\ n456\ n789\ naaa\ nbbb\ nccc" 123456789aaabbb [root@zhaocheng ~] # printf "% s\ n" 123456789aaabbb ccc123456789aaabbbccc
Printf also supports a variety of replacement character format types
% s string
% f floating point format
When the parameter corresponding to% b contains an escape character, it can be replaced with this substitution, and the escape character will be escaped.
% c ASCII character, showing the first character of the corresponding parameter
% d% I decimal integer
% o Octal value without a sign
% u decimal value without a plus or minus sign
% x is a hexadecimal value without a plus or minus sign, using a to f for 10 to 15
% X has no hexadecimal value with a plus or minus sign, using A to F for 10 to 15
% represents "%" itself
Escape character
Escape characters commonly used in printf
\ a warning character, usually the BEL character of ASCLL
\ b step back.
\ c suppresses (does not display) any escaped characters at the end of the output (valid only in parameter strings controlled by% b format indicator, and any characters left in parameters, any subsequent parameters and any characters left in format strings are ignored
\ f Page change
\ nWrap
\ r enter
\ t horizontal tabs
\ v Vertical tab character
\ a literal backslash character, valid only in format strings
\ 0ddd represents 1-3 octal value characters
For example, add a pair of parentheses for each incoming parameter, and the test inside the parentheses needs to have spaces
[root@zhaocheng ~] # printf "[% s]" 12 45 67 78 89; echo "[12] [45] [67] [78] [89] [root@zhaocheng ~] # printf" [% s] "12 45 67 78 89; echo"[12] [45] [67] [78] [89]
Separate with the\ t parameter "Tab"
[root@zhaocheng ~] # printf "% s\ t" 12 45 67 78 89; echo "" 12 45 67 78 89
Using\ nis newline output,% f\ nfloating point parameter output
[root@zhaocheng ~] # printf "% s\ n" 123455676 7612345567676 [root@zhaocheng ~] # printf "% f\ n" 123455676 76123.000045.0000566.000076.000000
The use of format substitutes
[root@zhaocheng ~] # printf "% s\ n" 12 4567 7889 9912 4567 7889 99 [root@zhaocheng ~] # printf "% s\ n" 12 4567 7889 9912 4567 [root@zhaocheng ~] # printf "% s% s\ n" 12456778899912 4567788999 [root@zhaocheng ~] # printf "% s% s\ n" 124567788991245677889 [root@zhaocheng ~] # printf " % s% s\ n "12 45 67 78 89 9912 45 67 78 8999 [root@zhaocheng ~] # printf"% s% s\ n "12 45 67 78 89 9912 45 67 78 8999 [root@zhaocheng ~] # printf" 12 45 67 78 8999\ n "12 45 67 78 8999
Printf can also be used for color output.
You can also add a specific number, and% 7s 7 means that the output width corresponding to the current replacement character is 7 characters wide.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.