In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article shares with you the content of the sample analysis of awk single quotes + shell variables + domain variables. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
[rdb@mdb tmp] $echo TOM | awk'{print "select * from A where name='\''" $1 "\'"}''
Select * from A where name='TOM'
[rdb@mdb tmp] $echo TOM | awk'{print "select * from A where name='\'" $1 "\'"}''
Select * from A where name='TOM'
[rdb@mdb tmp] $
The name part of both is enlarged as follows:
Name='\ "$1"\'"
Name='\ "$1"\'"
The former has two more single quotes before the $1 double quotation marks than the latter, but why do the two have the same effect? my understanding is that the two extra single quotes have no internal value and are empty, so the effect is the same. if you add a few more single quotes, for example:
Echo TOM | awk'{print "select * from A where name='\'" $1 "\'"}''
When referencing a concatenated field variable in awk's print, the variable should be enclosed in double quotation marks:
"$1"
Then add single quotation marks to the value, and each single quote needs to be escaped. The escape rule is: two single quotation marks, and then add\ 'inside it. After completion, it is:'\', and when enlarged is:'\'.
It's connected to:'$1'.
This is the second name='\'$1'\'
On the question of referencing shell variables:
To use the shell variable in awk, you need to use "'$a'" with double quotation marks and single quotation marks.
For example:
[rdb@mdb tmp] $axi10
[rdb@mdb tmp] $echo 90 | awk'{print "" $1 "/"'$a' "=" $1 / "" $a' "}'
90, 10, 10, 9.
[rdb@mdb tmp] $
Enlarged to: echo 90 | awk'{print "" $1 "/"'$a'"=" $1 / "" $a'"}'
Function getcmdstat_sql ()
{
Grep cmdstat_ 13_20170519102523.info_all | awk-F "[: =,] +" {print "insert into tbl_rdb_cmdstats (dc_area,node_name,node_ip,chk_time,statname,total_calls,total_timing) values ('\'${dc_area}'\', ${1}'\','\'${2}'\', to_date ('\'${fn_date}'\') '\' yyyy-mm-dd hh34:mi:ss'\'),'\'"$1"'\','\'"$3"'\', trunc ('"$5"'\'/ 1000amp 1000) "}'> > / tmp/c.sql
}
Getcmdstat_sql "$node_name"$node_ip"
-F "[: =,] +" represents:, =, "colon, equal sign, comma are all delimiters.
Thank you for reading! On "awk single quotation marks + shell variable + domain variable example analysis" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
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.