In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to use awk to parse ini files in Linux. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1 ini file
Ini files are text files that some software uses to save configuration information. The advantages of ini files are simplicity and flexibility, while the disadvantage is that there is no unified standard.
Let's look at an example of the contents of an ini file:
[Master] Arguments =-log master.logLogLevel = 3 [Client] Arguments =-log client.logLogLevel = 1
As you can see here, the contents of the ini file can be divided into different parts according to [Master] and [Client], each containing a set of key-value pairs. We can simply model the ini file:
An ini file is a text file that consists of a set of fields.
A domain consists of a domain name and a series of key-value pairs. The domain name and each key-value pair occupy one line respectively.
The format of the line of the domain name is "[domain name]".
The format of the row of key-value pairs in the field is "key = value".
Based on this model, the ini file can be parsed.
2 awk program
The following program iterates through each line of the ini file, outputting the read key-value pairs in "export scope_name=value" format.
# ini2env.awkfunction ltrim (s) {sub (/ ^ [\ t\ r\ n] + /, ", s); return s} function rtrim (s) {sub (/ [\ t\ r\ n] + $/,", s); return s} function trim (s) {return rtrim (ltrim (s));} BEGIN {scope= "" } {if ($1 ~ /\ [. *\] /) scope=trim (substr ($1 min2) Else {name=trim ($1) value=$2; if (length (value) > 0) {printf ("export% slots% s =\"% s\ "\ n", scope, name, value) } 3 use the example # ini file [app] arguments=-- debug# to convert the ini file into a temporary shell script. Tmpfile= `mktemp 'cat app.ini | awk-F' ='- f ini2env.awk > > $tmpfile# loads the sh script and sets the environment variables. Source $tmpfile# removes the temporary script. Rm $tmpfile# starts the program, passing in the ini parameter. App=./a.out$app $app_arguments above is the Linux that Xiaobian shares with you how to use awk to parse ini files. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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.