In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the use of linux printf command shell output, I believe that most people do not know much, so share this article for you to learn, I hope you will learn a lot after reading this article, let's go to learn the method!
The printf command mimics the printf () program in the C library (library).
Printf uses parameters separated by reference text or spaces, and you can use formatted strings in printf, and you can also specify the width of the string, left and right alignment, and so on. The default printf does not automatically add newline characters like echo, we can add\ n manually.
Syntax format: printf [format control string] [parameter]
Common parameters:
\ a warning character, usually ASCII's BEL character\ nnewline\ r carriage return\ 0ddd for 1 to 3 octal value characters\ ddd for 1 to 3 octal values. Valid only in format strings
Reference example
String output:
[root@linuxcool ~] # printf "Hello, Shell\ n" Hello, Shell
Next, I'll use a script to demonstrate the power of printf:
[root@linuxcool] # printf "%-10s%-8s%-4s\ n" name, gender and weight kgprintf "%-10s%-8s%-4.2f\ n" Guo Jing male 66.1234 printf "%-10s%-8s%-4.2f\ n" Yang Guo Nan 48.6543 printf "%-10s%-8s%-4.2f\ n" Guo Fu female 47.9876 "
Execute the script, and the output is as follows:
[root@linuxcool] # name, sex and weight kg Guo Jing male 66.12 Yang Guo male 48.65 Guo Fu female 47.99
S, c, d, f are all format substitutes
%-10s means a width of 10 characters (- for left alignment, none for right alignment), any character will be displayed in a 10 character width character, if it is insufficient, it will be automatically filled with spaces, and the excess will also display all the content.
%-4.2f refers to formatted as a decimal, where .2 means to retain 2 decimal places.
The format control string is in double quotes:
[root@linuxcool ~] # printf "% d% s\ n" 1 "abc"
The format control string is in single quotes:
[root@linuxcool ~] # printf'% d% s\ n'1 "abc"
You can output without quotation marks:
[root@linuxcool ~] # printf% s abcdef above is all the content output using linux's printf command shell, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.