In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to use linuxShell script to pass an array to awk for processing, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
How does the Shell script pass an array to the awk for processing?
Test environment:
[root] # head-1 / etc/redhat-releaseRed Hat Enterprise Linux Server release 6.5 (Santiago) [root] # awk-- version | head-1GNU Awk 3.1.7
As we all know, it is very simple to pass a normal variable to awk in a Shell script, simply assigning a value with the-v argument.
Str1= "Hello World" awk-v str2= "$str1" 'BEGIN {print str2}'
However, it's not that easy to pass an array to awk. Take a look at the following three experiments:
1. Simple arrays can be assigned first and then split
Arr1= (A B C) awk-v arr2= "${arr1 [*]}" 'BEGIN {split (arr2,arr3, "); print arr3 [2]}'
two。 In some cases, it is difficult to find the right delimiter for split, because an array element may contain the character you want to use as the delimiter, and split cannot get the desired result later. So this method is not rigorous enough, especially when we can't predict which characters an array element might contain.
Arr1= (A "B C" D) awk-v arr2= "${arr1 [*]}" 'BEGIN {split (arr2,arr3, "); print arr3 [2]}'
3. You can do this with the help of the export command and awk's ENVIRON default array
Arr1= (A "B C" D) for
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.