awk+手册中文版
awk中文手册
ENVIRON 环境变量关联数组。
ERRNO 最后一个系统错误的描述。
FIELDWIDTHS 字段宽度列表(用空格键分隔)。
FILENAME 当前文件名。
FNR 同NR,但相对于当前文件。
FS 字段分隔符(默认是任何空格)。
IGNORECASE 如果为真,则进行忽略大小写的匹配。
NF 当前记录中的字段数。
NR 当前记录数。
OFMT 数字的输出格式(默认值是%.6g)。
OFS 输出字段分隔符(默认值是一个空格)。
ORS 输出记录分隔符(默认值是一个换行符)。
RLENGTH 由match函数所匹配的字符串的长度。
RS 记录分隔符(默认是一个换行符)。
RSTART 由match函数所匹配的字符串的第一个位置。
6.3. 域分隔符
内建变量FS保存输入域分隔符的值,默认是空格或tab。我们可以通过-F命令行选项修改FS的值。如$ awk -F: '{print $1,$5}' test将打印以冒号为分隔符的第一,第五列的内容。
可以同时使用多个域分隔符,这时应该把分隔符写成放到方括号中,如$awk -F'[:\t]' '{print $1,$3}' test,表示以空格、冒号和tab作为分隔符。
匹配字符串末尾的一个空字符串。
8. POSIX字符集
可参考我的Grep学习笔记
9. 匹配操作符(~)
用来在记录或者域内匹配正则表达式。如$ awk '$1 ~/^root/' test将显示test文件第一列中以root开头的行。
那些年我用awk时踩过的坑——awk使用注意事项
那些年我⽤awk时踩过的坑——awk使⽤注意事项由于项⽬经历原因,经常使⽤awk处理⼀些⽂本数据。
甚⾄,我特意下载了⼀个windows上的awk:gawk.exe,这样在windows上也能享受awk处理数据的⽅便性,。
俗话说,“常在河边⾛,哪能不湿鞋”,使⽤awk过程中碰上过不少坑,这⾥稍总结⼀下,希望对⼤家有帮助。
1 FS问题看看这两个awk脚本:cat demo_1.txt demo_2.txt1|2|3|4|1|@|2|@|3|@|4|@|awk -F '|''{print $2}' demo_1.txt; # 脚本1awk -F '|@|''{print $2}' demo_2.txt; # 脚本2脚本原⽬的是达到的⽬的是分别按'|'和分隔'|@|',输出demo.txt第⼆列。
但实际上,第⼀个脚本这样写没错,但第⼆个脚本却是错的。
为什么呢?因为竖线在正则表达式中是⼀个特殊字符,表⽰匹配竖线左右的字符组之⼀。
如果想使⽤竖线本⾝,需要对⽤转义符。
但为什么第⼀个命令也⼀样使⽤了竖线却没有问题呢?这就涉及到awk在⼀个规定:如果FS设置了不⽌⼀个字符作为字段分隔符,将作为⼀个正则表达式来解释,否则直接按该字符做为分隔符对每⾏进⾏分割。
所以第⼀个命令使⽤了竖线做分隔符没问题,第⼆个命令就出错了。
2 正则表达式与反斜杠号问题继续上⾯的问题讨论,如果demo.txt是按"|@|"做为分隔符的,要输出demo.txt第⼆列,正确的答案应该是怎么写呢?答案是:awk -F '\\|@\\|''{print $2}' demo.txt;注意这⾥,FS的值是'\\|@\\|',⽽不是简单的'\|@\|'(这样写会报错,提⽰:awk: 警告: 转义序列“\|”被当作单纯的“|”)。
通过awk命令统计文件中的行数字数和字符数
通过awk命令统计文件中的行数字数和字符数awk是一种强大的文本处理工具,它可以方便地对文件进行分析和处理。
在本文中,我们将使用awk命令来统计文件中的行数和字符数。
使用awk命令统计行数和字符数的基本语法是:```awk '{行数计数器++} {字符数计数器+=length($0)} END {print "行数:"行数计数器, "字符数:"字符数计数器}' 文件名```其中,`行数计数器++`用于统计行数,每当awk读取一行文本时,行数计数器会自动加1。
`字符数计数器+=length($0)`用于统计字符数,每当awk读取一行文本时,字符数计数器会自动加上该行的字符数。
下面是一个示例,我们将使用awk命令统计一个名为example.txt的文件中的行数和字符数:```awk '{lines++} {chars+=length($0)} END {print "行数:" lines, "字符数:" chars}' example.txt```以上命令将输出文件example.txt中的行数和字符数。
实际使用中,我们可以将以上命令封装成一个shell脚本,以方便多次使用和批量处理。
以下是一个简单的shell脚本示例:```shell#!/bin/bash# 输入文件名read -p "请输入文件名: " filename# 统计行数和字符数count=$(awk '{lines++} {chars+=length($0)} END {print "行数:" lines, "字符数:" chars}' $filename)# 输出统计结果echo $count```保存脚本为count_lines_chars.sh,并给予执行权限。
Moxa AWK-1137C 产品说明书
P/N: 1802011370017 *1802011370017*AWK-1137C Series Quick Installation GuideMoxa AirWorksVersion 7.1, January 2021Technical Support Contact Information/support2021 Moxa Inc. All rights reserved.OverviewThe AWK-1137C industrial Wi-Fi client meets the growing need for faster data transmission speeds and wider coverage by supporting IEEE 802.11n technology with a net data rate of up to 300 Mbps. TheAWK-1137C combines two adjacent 20 MHz channels into a single 40 MHz channel to deliver a potent combination of greater reliability and more bandwidth. The AWK-1137C can operate on either the 2.4 GHz or the 5 GHz band and is backward compatible with existing 802.11a/b/g deployments.Hardware SetupThis section covers the hardware setup for the AWK-1137C. Package ChecklistBefore installing the AWK-1137C, verify that the package contains the following items. If any of these items is missing or damaged, please contact your customer service representative for assistance.• 1 AWK-1137C wireless client• 2 2.4/5 GHz omni-directional antennas: ANT-WDB-ARM-0202 •DIN-rail kit•Quick installation guide (printed)•Warranty cardPanel Layout of the AWK-1137C1.System LEDs: SYS, WLAN,LAN1, LAN2, and SERIALN1: 10/100 BaseT(X) RJ45portN2: 10/100 BaseT(X) RJ45port4.RS-232/422/485 DB9 serial port5.3-pin terminal block(ground/-/+)6.M3 screw holes for antennabracket7.Antenna B RP-SMA8.Antenna A RP-SMA9.3-pin maintenance port forengineers10.Reset button11.Screw holes for DIN-railmounting kit12.Screw holes for wall-mountingkitMounting DimensionsDIN-Rail MountingWhen shipped, the metal DIN-rail mounting kit is fixed to the back panel of the AWK-1137C. Mount the AWK-1137C on the corrosion-free mounting rail that adheres to the EN 60715 standard.STEP 1:Insert the upper lip of the DIN-rail kit into the mounting rail. STEP 2:Press the AWK-1137C towards the mounting rail until it snaps into place.Unit = mm (inch)To remove the AWK-1137C from the DIN rail, do the following: STEP 1:Pull down the latch on theDIN-rail kit with a screwdriver.STEP 2 & 3: Slightly pull theAWK-1137C forward and lift it up to remove it from the mounting rail.Wall Mounting (Optional)For some applications, it may be more convenient to mount the AWK-1137C to a wall, as illustrated below: STEP 1:Remove the aluminum DIN-rail attachment plate from theAWK-1137C, and then attach thewall-mounting plates with M3 screws, as shown in the adjacent diagrams.STEP 2: Mounting the AWK-1137C to a wall requires two screws. Use the AWK-1137C device, withwall-mounting plates attached, as a guide to mark the correct locations of the two screws. The heads of the screws should be less than 6.0 mm in diameter, and the shafts should be less than 3.5 mm in diameter, as shown in the figure on the right.Do not drive the screws in all the way—leave a space of about 2 mm to allow room for sliding the wall-mounting panel between the wall and the screws.NOTE Test the screw head and shank size by inserting the screws into one of the keyhole-shaped apertures of the wall-mounting platesbefore they are fixed to the wall.STEP 3a:Once the screws are fixed into the wall, insert the two screw heads through the large opening of the keyhole-shaped apertures, and then slide the AWK-1137C downwards, as indicated to the right. Tighten the two screws for added stability.STEP 3b:Alternatively, insert four screws directly through the AWK-1137C into the wall.WARNING•This equipment is intended to be used in a Restricted Access Location, such as a dedicated computer room where only authorized service personnel or users can gain access. Such personnel must be instructed about the fact that the metal chassis of the equipment is extremely hot and may cause burns.• Service personnel or users have to pay special attention and take special precautions before handling this equipment. •Only authorized, well-trained professionals should be allowed to access the Restricted Access Location. Access should be controlled by the authority responsible for the location with a lock and key or a security identity system.•External metal parts are hot!! Pay special attention or use special protection before handling this equipment.Wiring RequirementsYou should also pay attention to the following items:•Use separate paths to route wiring for power and devices. If power wiring and device wiring paths must cross, make sure the wires are perpendicular at the intersection point.NOTE Do not run signal or communications wiring and power wiring in the same wire conduit. To avoid interference, wires with differentsignal characteristics should be routed separately.•You can use the type of signal transmitted through a wire to determine which wires should be kept separate. The rule of thumb is that wiring with similar electrical characteristics can be bundledtogether.•Keep input wiring and output wiring separate.•It is strongly advised that you label wiring to all devices in the system when necessary.Grounding the Moxa AWK-1137CGrounding and wire routing help limit the effects of noise due toelectromagnetic interference (EMI). Run the ground connection from the ground screw to the grounding surface prior to connecting devices.Installing Cable Extended Antennas for Outdoor Applications If the antenna or the AWK device is installed outdoors or in an open-air setting, proper lightning protection is required to prevent direct lightning strikes on the AWK device. In order to prevent coupling currents from nearby lightning strikes, a lightning arrester should be installed as part of your antenna system. Ground the device, antenna, as well as the arrester properly to provide maximum outdoor protection for the device.Arrester Accessories • SA-NMNF-01: Surge arrester, N-type (male) to N-type (female) • SA-NFNF-01: Surge arrester, N-type (female) to N-type (female)Wiring the Power InputThe 3-contact terminal block connector on the AWK-1137C’s side panel is used for the AWK-1137C’s DC input. The top and front views of the terminal block connector are shown below:STEP 1:terminals.STEP 2:To keep the DC wires from pulling loose, use a smallflat-blade screwdriver to tighten the wire-clampscrews on the front of the terminal block connector.STEP 3:Insert the plastic terminal block connector prongsinto the terminal block receptor, which is located onthe AWK-1137C’s side panel.NOTE Input Terminal Block (CN1) is suitable for wire size range of 12-28 AWG (3.31-0.0804 mm²) and a torque value of 4.5 lb-in(0.51 Nm)Using the Reset ButtonThe Reset button is used to load the factory default settings. Use apointed object to hold the Reset button down for five seconds to load the factory defaults.Activating AeroMag FunctionPush the Reset Button five times to activate AeroMag. To deactivate it again, push the Reset Button three times.Installing the Antenna-Locking ClampUse the antenna-locking clamp to secure the antennas to the AWK-1137C for added stability when you install the device in a high-vibration environment.STEP 1: Slide the locking clamps through the antenna ports. STEP 2: Use screws to fix the clamps to the side panel of the AWK-1137C asshown below:Communication Connections10/100BaseT(X) Ethernet Port ConnectionThe 10/100BaseT(X) ports located on the AWK-1137C’s front panel are used to connect to Ethernet-enabled devices.The pinouts for both the MDI (NIC-type) and MDI-X (HUB/switch-type) ports as shown below:MDI Port Pinouts MDI-X Port Pinouts8-pin RJ45Pin Signal 1 Tx+ 2 Tx- 3 Rx+ 6 Rx-Pin Signal 1 Rx+ 2 Rx- 3 Tx+ 6 Tx-RS-232/422/485 Serial PortThe AWK-1137C has 1 RS-232/422/485 serial port with DB9 connectorfor serial-to-WLAN connectivity. The pin assignments for the serial ports are shown below: PinRS-232RS-422/485(4W) RS-485 (2W) 1 DCD TxD-(A) – 2 RxD TxD+(B) –3 TxD RxD+(B) Data+(B)4 DTR RxD-(A) Data-(A)5 GND GND GND6 DSR – –7 RTS – –8 CTS – – 9–––LED IndicatorsThe front and side panel of the Moxa AWK-1137C contains several LED indicators. The function of each LED is described in the table below: LED Color StateDescription SYSGreen OnSystem start up complete and the system is in operationBlinking + Beeps (Interval: 1 second) Device has been located by the Wireless Search Utility RedOn System is booting or a system booting error has occurred Blinking (Interval: 0.5 second)IP address conflict Blinking (Interval: 1 second) Cannot obtain an IP address from the DHCP server WLANGreenOn (RSSI > 35) WLAN interface has connected Blinking Data communication via WLAN AmberOn (RSSI < 35) WLAN interface has connected Blinking Data communication via WLAN LAN1 GreenOn Ethernet LAN 1 interface has connected Blinking Data communication via Ethernet LAN 1 LAN2 GreenOn Ethernet LAN 2 interface has connected Blinking Data communication via Ethernet LAN 2 Serial Amber Blinking Data Transmission via serial data port SpecificationsPower Input9 to 30 VDC PowerConsumption11.7 W OperatingTemperatureStandard Models: 0 to 60°C (32 to 140°F) Wide Temp. Models: -40 to 75°C (-40 to 167°F) StorageTemperature-40 to 85°C (-40 to 185°F)NOTE For installation flexibility, you may select either antenna A or antenna B on the top panel. Make sure the antenna connectionmatches the antennas configured in the AWK-1137C webinterface.To protect the connectors and RF module, all radio ports shouldbe terminated by either an antenna or a terminator. We stronglyrecommend using resistive terminators for terminating theunused antenna ports.Federal Communications Commission Interference StatementThis equipment has been tested and found to comply with the limits for a Class B digital device, pursuant to part 15 of the FCC Rules. These limits are designed to provide reasonable protection against harmful interference in a residential installation. This equipment generates, uses, and can radiate radio frequency energy and, if not installed and used in accordance with the instructions, may cause harmful interference to radio communications. However, there is no guarantee that interference will not occur in a particular installation.If this equipment does cause harmful interference to radio or television reception, which can be determined by turning the equipment off and on, the user is encouraged to try to correct the interference by one or more of the following measures:•Reorient or relocate the receiving antenna.•Increase the separation between the equipment and receiver. •Connect the equipment into an outlet on a circuit different from that to which the receiver is connected.•Consult the dealer or an experienced radio/ TV technician for help.Software SetupThis section covers the software setup for AWK models in general. How to Access the AWKBefore installing the AWK device (AWK), make sure that all items in the package checklist are provided in the product box. You will also need access to a notebook computer or PC equipped with an Ethernet port. •Step 1: Select a suitable power source and plug in the AWK.The AWK can be powered by DC power ranging from 9 VDC to 30 VDC.•Step 2: Connect the AWK to the notebook or PC via the AWK’s LAN port.The LED indicator on the AWK’s LAN port will light up when aconnection is established.NOTE If you are using an Ethernet-to-USB adapter, follow the instructions in the user’s manual provided with the adapter.•Step 3: Set up the computer’s IP addressChoose an IP address for the computer that is on the same subnet as the AWK. Since the AWK’s default IP address is 192.168.127.253, and the subnet mask is 255.255.255.0, set the IP address to192.168.127.xxx, where xxx is a value between 1 and 252. •Step 4: Access the homepage of the AWK.Open your computer’s web browser and typehttp://192.168.127.253 in the address field to access the AWK’s homepage. Log in using the following default username andpassword:Default Username: adminDefault Password: moxaClick the Login button to access the homepage of the AWK device.First-Time Quick ConfigurationAfter successfully accessing the AWK, refer to the appropriate subsection below to quickly set up a wireless network.NOTE Ensure that there are no IP address conflicts when you configure more than one AWK on the same subnet.Point-to-Multipoint Scenario (Client Mode)Configuring the AWK as a Client•Step 1: Set the operation mode of the AWK to Client mode.Go to Wireless LAN Setup→Operation Mode, select Client and click Submit to apply the change.NOTE The default operation mode for the AWK is Client.•Step 2: Link to an existing SSID.Go to Wireless LAN Setup→WLAN→Basic WLAN Setup and click Site Survey to select an existing SSID, or directly enter anexisting SSID in the text field.The default SSID is MOXA.•Step 3: Set the RF type and Channel settings for the AWK.On the Wireless LAN Setup→WLAN→Basic WLAN Setup page, edit the RF type and Channel settings.Click Submit to apply the changes, and restart the AWK in client mode to complete the configuration process.Point-to-Point Scenario (Slave mode)Configuring the AWK as a Slave•Step 1: Set the operation mode of the AWK to Slave mode.Go to Wireless LAN Setup→Operation Mode, set the operation mode to Slave, and then click Submit to apply the change.•Step 2: Link to an existing SSID.Go to Wireless LAN Setup→WLAN→Basic WLAN Setup and click Site Survey to select an existing SSID, or directly enter anexisting SSID in the text field.•Step 3: Set the RF type for the AWK.On the Wireless LAN Setup→WLAN→Basic WLAN Setup page edit the RF type setting.Click Submit to apply the changes, and restart the AWK in slavemode to complete the configuration process。
awk+手册中文版
awk+手册中文版Awk+手册中文版1、简介Awk是一种强大的文本处理工具,它可以进行数据提取和报表。
Awk的基本思想是将输入数据拆分为记录并逐行处理。
本章将介绍Awk的概述、发展历史和主要特点。
2、安装和配置本章将介绍如何安装Awk以及配置相关环境变量。
还将介绍一些常见的问题和解决方法。
3、Awk语法本章将详细介绍Awk的基本语法,包括模式匹配、变量使用、运算符、控制结构、函数等。
通过本章的学习,读者将掌握编写Awk脚本的基本技巧。
4、Awk模式本章将介绍Awk的模式匹配方法,包括正则表达式、关系运算符、逻辑运算符等。
通过本章的学习,读者将了解如何在Awk中进行高级模式匹配。
5、Awk内置函数本章将介绍Awk内置的各种函数,包括字符串处理函数、数学函数、时间函数等。
通过本章的学习,读者将了解如何在Awk中利用内置函数进行快速数据处理。
6、Awk高级技巧本章将介绍一些Awk的高级技巧,包括数组的使用、多文件处理、系统调用等。
通过本章的学习,读者将了解如何在复杂的数据处理场景中发挥Awk的威力。
7、Awk实例应用本章将提供一些实际应用的例子,包括文件处理、日志分析、数据提取等。
通过本章的学习,读者将了解如何灵活运用Awk解决实际问题。
8、Awk调试与优化本章将介绍一些调试和优化Awk脚本的方法,包括调试输出、性能优化等。
通过本章的学习,读者将提高Awk脚本的效率和可靠性。
9、Awk常见问题解答本章将总结一些Awk常见问题,并提供相应的解答。
通过本章的学习,读者将解决在使用Awk过程中遇到的一些困惑。
10、附录:Awk语法速查表本附录提供了一个Awk语法速查表,方便读者在实际使用中快速查找语法相关内容。
附件:本文档涉及的附件包括一些示例代码、测试文件等,以帮助读者更好地理解和学习Awk的应用。
法律名词及注释:1、Awk:一种文本处理工具,根据指定的规则对文本进行分析和处理。
2、模式匹配:根据特定的模式对文本进行匹配,以进行相应的处理。
awk system 参数
awk system 参数awk是一种强大的文本处理工具,在Linux环境下广泛使用。
它具有很强的过滤和操作文本的能力,同时可以与Linux系统进行良好的集成,如使用awk system参数执行系统命令。
下面我们将分步骤阐述awk system参数的详细使用方法:步骤一:了解awk命令的基本语法awk命令的基本语法如下:>awk [选项参数] 'pattern{action}' file其中的pattern表示模式匹配,action表示需要执行的操作。
它的工作原理是从文件file中逐行读取并处理,根据模式匹配执行对应的操作。
步骤二:使用awk system参数执行系统命令awk系统参数可以与awk命令集成,用于执行系统命令。
system参数的基本语法如下:>system("command")其中的command表示需要执行的系统命令。
使用awk system参数可以在awk程序中执行任何有效的Linux系统命令。
例如,我们可以在awk程序中使用system参数来执行系统命令ls,可以将当前目录下的文件名列出来,如下所示:$ ls | awk '{print $1}' # 输出当前目录下的文件名另外,我们还可以在awk程序中使用system参数来执行Linux命令df,可以列出磁盘分区的统计信息,如下所示:$ df | awk '{print $1,$2,$3}' # 输出df命令输出的磁盘分区信息步骤三:使用awk system参数进行文件操作awk system参数还可以用于执行文件操作。
例如,我们可以在awk程序中使用system参数来运行Linux命令touch,可以创建一个新文件,如下所示:$ awk 'BEGIN{system("touch test.txt")}' # 创建一个新文件test.txt我们还可以在awk程序中使用system参数来执行Linux命令rm,可以删除一个指定的文件,如下所示:$ awk 'BEGIN{system("rm test.txt")}' # 删除test.txt文件总结以上就是awk system参数的详细使用方法。
很全的sed&awk 正则表达式手册
Sed (2)sed常用选择项 (2)语法正则表达式 (3)替换 (6)删除 (7)追加插入更改 (7)列表 (7)转换 (7)打印 (7)打印行号 (8)下一步 (8)读和写文件 (8)退出 (8)高级命令 (8)awk (14)分隔符 (14)表达式字符链接 (14)系统内置变量 (16)格式化输出 (17)使用shell 变量 (18)流控制 (18)数组 (20)测试数组成员 (21)函数 (22)高级讲解 (24)域 (24)变量 (26)特殊模式begin end (27)命令参数 (28)Sed 命令sed常用选择项sed/awk +[参数选项]+ “语法“+ 文件名-n 关闭输出到标准输出-e 执行多条sed命令;(或者用“;”间隔多条指令)-f 从命令脚本读如命令Sed –f sed_srcript_file input_filesed/awk的特点均是读入文件的一行做为输入,应用于所有的命令,再读入下一行执行操作:1 从输入文件中读入一行2 为改行做一个拷贝3 在该行上执行“语法”动作4 为下一行执行第一步动作语法正则表达式/pattern/actionPattern 正则表达式Action 执行动作执行过程:1 顺序收索每个模式pattern 直到发现一个匹配2 发现匹配后执行action 动作3 执行完成后,到达下一个action ,执行第一步4 当所有模式试过一遍后,读取下一行。
在第四步前,sed显示被改动的记录,awk必须手动显示改动的内容,Sed可以使用的动作包括编辑单个字母的命令,awk动作通常是一个编程语句集合。
Pattern 包括普通字符和通配符。
. 点号* 星号在此处意思是匹配前面字符出现0次以上[chars] 匹配chars中的任何一个字符,chars是一个字符序列。
可用“-”字符指出字符范围,“^”是chars中的第一个字符,则匹配未在chars中指定的字符^ 匹配一行的开始$ 匹配一行的末\ 转义符号[…] 匹配括弧里面的任意字符,第一字符如果是^表示不包含所列示字符,如果里面包含‟[ ]‟符号时候,表示同时包含‟[]‟,如果是任选之一应写成‟][‟\{n, m\} 匹配前面的匹配n-m次;\{n\}匹配前面的模式n次Egrep 和awk 可以使用的特殊字符…\<‟…\>‟+ 匹配前面的正则表达式1次以上? 匹配前面的正则表达式0次以上| 匹配前面或者后的表达式( ) 对正则表达式分组,设置匹配集合Sed是先对第一个行应用所有编辑命令,在对第二个行。
Sed and Awk 101 Hacks -中文版
莫克AWK-3121无线访问点说明书
P/N: 1802031210017 *1802031210017*AWK-3121Quick Installation GuideMoxa AirWorksEdition 8.0, September 2016Technical Support Contact Information/supportMoxa Americas:Toll-free: 1-888-669-2872 Tel: 1-714-528-6777 Fax: 1-714-528-6778 Moxa China (Shanghai office): Toll-free: 800-820-5036 Tel: +86-21-5258-9955 Fax: +86-21-5258-5505 Moxa Europe:Tel: +49-89-3 70 03 99-0 Fax: +49-89-3 70 03 99-99 Moxa Asia-Pacific:Tel: +886-2-8919-1230 Fax: +886-2-8919-1231 Moxa India:Tel: +91-80-4172-9088 Fax: +91-80-4132-10452016 Moxa Inc. All rights reserved.OverviewThe AWK-3121 Access Point (AP) is ideal for hard-to-wire industrial applications. The AP keeps wireless costs under control and integrates with existing mobile equipment. The AWK-3121 is compliant with the industrial standards and approvals covering operating temperature, power input voltage, surge, ESD, and vibration. Installation is easy with DIN-rail mounting capability for installation in distribution boxes. The DIN-rail mounting capability, wide operating temperature range, andIP30 housing with LED indicators make the AWK-3121 a convenient yet reliable solution for any industrial wireless application.Package ChecklistMoxa’s AWK-3121 is shipped with the following items. If any of these items is missing or damaged, please contact your customer service representative for assistance.• 1 AWK-3121• 2 Dual-band omni-directional antennas (2 dBi, RP-SMA, 2.4 a 5 GHz) • 1 Cable holder with a screw• 2 Protective caps•Quick installation guide (printed)•Warranty cardPanel Layout of the AWK-31211.Grounding screw2.Terminal block for PWR1, PWR2,relay, DI1, and DI23.Reset button4.Heat dissipation orifices5.System LEDs: PWR1, PWR2,PoE (discontinued starting withHW Rev 2.0.0), FAULT, andSTATE LEDs6.LEDs for signal strength7.WLAN LEDs: CLIENT, BRIDGE,and WLAN LEDs8.RS-232 console port9.10/100BaseT(X) RJ45 Port10.10M LED11.100M LED12.MAIN antenna port13.AUX antenna port14.Model name15.Screw hole for wall-mounting kit16.DIN-rail mounting kitMounting DimensionsUnit = mm (inch)DIN-Rail MountingThe aluminum DIN-rail attachment plate should be fixed to the back panel of the AWK-3121 when you take it out of the box. If you need to reattach the DIN-rail attachment plate to the AWK-3121, make sure the stiff metal spring is situated towards the top, as shown in the figures below. STEP 1:Insert the top of the DIN rail into the slot just below the stiff metal spring.STEP 2:The DIN-rail attachment unit will snap into place as shown below.To remove the AWK-3121 from the DIN rail, simply reverse Steps 1 and 2.Wall Mounting (optional)For some applications, it may be more convenient to mount the AWK-3121 to a wall, as illustrated below. STEP 1:Remove the aluminum DIN-rail attachment plate from the AWK-3121, and then attach the wall- mounting plates with M3 screws, as shown in the adjacent diagrams.STEP 2: Mounting the AWK-3121 to a wall requires 4 screws. Use the AWK-3121 device, with wall-mounting plates attached, as a guide to mark the correct locations of the 4 screws. The heads of the screws should be less than 6.0 mm in diameter, and the shafts should be less than 3.5 mm in diameter, as shown in the figure at the right.Do not drive the screws in all the way into the wall—leave a space of about 2 mm to allow room for sliding the wall-mounting panel between the wall and the screws.NOTE Test the screw head and shank size of the screws by inserting the screws into one of the keyhole shaped apertures of the wall-mounting plate before attaching the plate to the wall.STEP 3:Once the screws are fixed into the wall, insert the four screw heads through the large opening of the keyhole-shaped apertures, and then slide the AWK-3121 downwards, as indicated to the right. Tighten the four screws for added stability.Wiring RequirementsYou should also pay attention to the following items:•Use separate paths to route wiring for power and devices. If power wiring and device wiring paths must cross, make sure the wires are perpendicular at the intersection point.NOTE Do not run signal or communications wiring and power wiring in the same wire conduit. To avoid interference, wires with differentsignal characteristics should be routed separately.•You can use the type of signal transmitted through a wire to determine which wires should be kept separate. The rule of thumb is that wiring with similar electrical characteristics can be bundledtogether.•Keep input wiring and output wiring separate.•It is strongly advised that you label wiring to all devices in the system when necessary.Grounding the Moxa AWK-3121Grounding and wire routing help limit the effects of noise due to electromagnetic interference (EMI). Run the ground connection from the ground screw to the grounding surface prior to connecting devices.Installations with Unstable Power InputsThere are cases where the device has to be wired to the same power source as other equipment. In such cases if equipment such as motors that are connected in the circuit draw a large amount of current during operation, the transient voltage drop could potentially cause the AWK to become unstable. Installing a DC/DC power isolator in between the two equipment is recommended to isolate the transient effect and to ensure a stable power input for the AWK.Installations with Cable Extended Antennas for Outdoor ApplicationsIf the antenna or the AWK device is installed outdoors or in an open-air setting, proper lightning protection is required to prevent direct lightning strikes on the AWK device. In order to prevent coupling currents from nearby lightning strikes, a lightning arrester should be installed as part of your antenna system. Ground the device, antenna, as well as the arrester properly to provide maximum outdoor protection for the device.Arrester Accessories•SA-NMNF-01: Surge arrester, N-type (male) to N-type (female) •SA-NFNF-01: Surge arrester, N-type (female) to N-type (female)Wiring the Redundant Power InputsThe top two pairs of contacts of the 10-contact terminal block connector on the AWK-3121’s top panel are used for the AWK-3121’s two DC inputs. Top and front views of the terminal block connector are shown here.STEP 1: Insert the negative/positive DC wires Array into the V-/V+ terminals.STEP 2: To keep the DC wires from pulling loose,use a small flat-blade screwdriver to tighten thewire-clamp screws on the front of the terminalblock connector.STEP 3: Insert the plastic terminal blockconnector prongs into the terminal blockreceptor, which is located on the AWK-3121’s toppanel.Wiring the Relay ContactThe AWK-3121 has one relay output, which consists of the two contacts of the terminal block on the AWK-3121’s top panel. Refer to the previous section for detailed instructions on how to connect the wires to the terminal block connector, and how to attach the terminal block connector to the terminal block receptor. These relay contacts are used to indicate user-configured events. The two wires attached to the Relay contacts form an open circuit when a user-configured event is triggered. If a user-configured event does not occur, the Relay circuit will be closed. Wiring the Digital InputsThe AWK-3121 has two sets of digital input—DI1 and DI2. Each DI comprises two contacts of the 10-pin terminal block connector on the AWK-3121’s top panel. You can refer to the “Wiring the Redundant Power Inputs” section for detailed instructions on how to connect the wires to the terminal block connector, and how to attach the terminal block connector to the terminal block receptor.Cable Holder Installation (Optional)You can attach the cable holder to the bottom of the AWK-3121. This helps to keep cabling neat and avoid accidents that result from untidy cables.STEP 1: Screw the cable holder onto the bottom of the AWK-3121.STEP 2: After mounting the AWK-3121 and plugging in the LAN cable, tighten the cable along the device and wall.Communication Connections10/100BaseT(X) Ethernet Port ConnectionThe 10/100BaseT(X) ports located on the AWK-3121’s front panel are used to connect to Ethernet-enabled devices.Below we show pinouts for both MDI (NIC-type) ports and MDI-X (HUB/Switch-type) ports.MDI Port Pinouts MDI-X Port Pinouts 8-pin RJ45RS-232 ConnectionThe AWK-3121 has one RS-232 (8-pin RJ45) console port located on the front panel. Use either an RJ45-to-DB9 or RJ45-to-DB25 cable to connect the Moxa AWK-3121’s console port to your PC’s COM port. You may then use a console terminal program to access the AWK-3121 for console configuration.Console Pinouts for 10-pin or 8-pin RJ45NOTE1. The pin numbers for the DB9 and DB25 male connectors,and hole numbers for the DB9 and DB25 female connectors are labeled on the connector strip. However, the numbers are typically quite small, so you may need to use a magnifying glass to see the numbers clearly.2. The pin numbers for both 8-pin and 10-pin RJ45 connectors(and ports) are typically not labeled on the connectors (or ports). Refer to the pinout diagram above for details.ATEX Information1. DEMKO certification number: 10 ATEX 0902666X2. Ambient range: -40°C ≤ Tamb ≤ 75°C3. Certification string: Ex nA IIC T4 Gc4.Standards covered:EN60079-0:2006+A11:2013, EN60079-15:2005 5. The conditions of safe usage:• The Ethernet Communication Devices are intended for mountingin an IP54 enclosure and used in an area of not more than pollution degree 2 as defined by IEC60664-1.• Conductors suitable for use in an ambient temperature greaterthan 93°C must be used for the Power Supply Terminal. • A 4 mm 2 conductor must be used when connection to theexternal grounding screw is utilized.• Cables must be suitable for use in an ambient temperaturegreater than 93°C.LED IndicatorsThe front panel of the Moxa AWK-3121 contains several LED indicators. The function of each LED is described in the table below.SpecificationsNOTE For installation flexibility, either the MAIN antenna or the AUX antenna may be selected for use. Make sure the antennaconnection matches the antennas configured in the AWK-3121web interface.To protect the connectors and RF module, all radio ports shouldbe terminated by either an antenna or a terminator. We stronglyrecommend using resistive terminators for terminating theunused antenna ports.。
Awk实例教程(中文版)
username: halt
uid:7
username: operator
uid:11
username: root
uid:0
username: shutdown
uid:6
username: sync
uid:5
username: bin
uid:1
....etc.
外部脚本
将脚本作为命令行自变量传递给 awk 对于小的单行程序来说是非常简单的,而对于多行程
现在,解释 { print } 代码块。在 awk 中,花括号用于将几块代码组合到一起,这一点类 似于 C 语言。在代码块中只有一条 print 命令。在 awk 中,如果只出现 print 命令,那 么将打印当前行的全部内容。
这里是另一个 awk 示例,它的作用与上例完全相同:
$ awk '{ print $0 }' /etc/passwd
$ awk '{ print "hiya" }' /etc/passwd
运行这个脚本将在您的屏幕上写满 hiya。:)
多个字段 awk 非常善于处理分成多个逻辑字段的文本,而且让您可以毫不费力地引用 awk 脚本中每 个独立的字段。以下脚本将打印出您的系统上所有用户帐户的列表:
$ awk -F":" '{ print $1 }' /etc/passwd
BEGIN { x=0 } /^$/ { x=x+1 } END { print "I found " x " blank lines. :)" }
在 BEGIN 块中,将整数变量 x 初始化成零。然后,awk 每次遇到空白行时,awk 将执行 x=x+1 语句,递增 x。处理完所有行之后,执行 END 块,awk 将打印出最终摘要,指出它 找到的空白行数量。
moxa awk1137C设置NAT测试手册
moxa awk1137C设置NAT测试手册
NAT测试手册一般包括以下内容:
(1)本NAT测试的目的与功用
(2)本NAT测试的理论依据
(3)实施NAT测试的方法,包括:何种NAT测试;内分几部分;每部分有多少个NAT测试项目;答案如何做,等等。
(4)NAT测试的标准答案和评分方法
(5)关于NAT测试的信度、效度资料的说明
(6)常模表,即如何依据常模解释NAT测试结果
二、NAT测试构成与使用
1、构成本NAT测试共有72道题,分6组,每组12题,每组难度逐步增加,每组内部题目也是由易到难排列。
每组题目所用解题思路基本一致,而各组之间则有差异。
可以测定知觉辩别力、图形比较、图形想象、类同、比较、图形组合、推理、系列关系、图形套合和互换等推理能力。
一般来说完成前面的题目对解决后面题目有帮助,完成先前一组题目也对后面各组题目的解答有学习效应。
这正是题目排列的用意所在。
每个NAT测试题目都有一定的主题图,但每张大的主题图中都缺少一部分,从主题图下6~8张小图片中选一张小图片填补在主题图的缺失部分,可使整个图案合理完整。
进行测试的任务就是从每题下面所给的小图片中找出合适于填补大图案的一张,并把该小图片的
序号填入答卷纸内相应题目号下面。
2、使用为每个被试准备一张答卷纸,一个NAT测试图册,提供或要求被试者自备铅笔一枝。
linux下awk命令使用详解(实例)
linux下awk命令使用详解(实例)linux下awk命令使用详解(实例)分类: shell编程开发 2012-04-27 18:15 112人阅读评论(0) 收藏举报最近在搞linux系统脚本文件时,遇到了AWK以前培训的时候没有注意还有这样的命令,这里学习并整理了下!一、awk命令行模式:第一种,命令行方式,如:awk [-Ffield-separator] 'commands' input-file(s)这里commands是真正的awk命令,[-F域分隔符]是可选的,awk 默认使用空格分隔,因此如果要浏览域间有空格的文本,不必指定这个选项,但如果浏览如passwd文件,此文件各域使用冒号作为分隔符,则必须使用-F选项:awk -F : 'commands' input-file第二种,将所有awk命令插入一个文件,然后用awk命令解释器作为脚本的首行,以便通过键入脚本名称来调用它。
第三种,将所有awk命令插入一个单独文件,然后调用:awk -f awk-script-file input-file-f选项指明在文件awk-script-file的awk脚本,input-file是使用awk进行浏览的文件名awk脚本:awk脚本由各种操作和模式组成,根据分隔符(-F选项),默认为空格,读取的内容依次放置到对应的域中,一行一行记录读取,直到文件尾模式和动作:任何awk语句都是由模式和动作组成,在一个awk脚本中可能有许多语句。
模式部分决定动作语句何时触发及触发事件。
动作即对数据进行的操作,如果省去模式部分,动作将时刻保持执行状态模式可以是任何条件语句或复合语句或正则表达式,模式包含两个特殊字段BEGIN和END,使用BEGIN语句设置计数和打印头,BEGIN语句使用在任何文本浏览动作之前,之后文本浏览动作依据输入文件开始执行;END语句用来在awk 完成文本浏览动作后打印输出文本总数和结尾状态标志,有动作必须使用{}括起来实际动作在大括号{}内指明,常用来做打印动作,但是还有更长的代码如if和循环looping语句及循环退出等,如果不指明采取什么动作,awk默认打印出所有浏览出的记录域和记录:awk执行时,其浏览标记为$1,$2...$n,这种方法称为域标记.使用$1,$3表示参照第1和第3域,注意这里使用逗号分隔域,使用$0表示使用所有域例:awk'{print $0}' temp.txt >sav.txt 表示打印所有域并把结果重定向到sav.txt中awk '{print $0}' temp.txt|tee sav.txt 和上例相似,不同的是将在屏幕上显示出来awk '{print $1,$4}'temp.txt 只打印出第1和第4域awk 'BEGIN {print "NAME GRADE\n-------------"} {print $1"\t"$4}'temp.txt表示打信息头,即输入的内容的第一行前加上"NAMEGRADE\n-------------",同时内容以tab分开awk 'BEGIN {print "being"} {print $1} END {print "end"}' temp 同时打印信息头和信息尾条件操作符:<、<=、==、!=、>=、~匹配正则表达式、!~不匹配正则表达式匹配:awk'{if ($4~/ASIMA/) print $0}' temp 表示如果第四个域包含ASIMA,就打印整条awk '$0 ~ /ASIMA/' temp 表示只要整条包含ASIMA就打印出来精确匹配:awk'$3=="48" {print $0}'temp 只打印第3域等于"48"的记录不匹配:awk '$0 !~ /ASIMA/'temp 打印整条不包含ASIMA的记录不等于:awk '$1 != "asima"' temp小于:awk '{if ($1<$2) print $1 "is smaller"}'temp设置大小写:awk '/[Gg]reen/'temp 打印整条包含Green,或者green的记录任意字符:awk '$1 ~/^...a/'temp 打印第1域中第四个字符是a的记录,^行首,.任意字符或关系匹配:awk '$0~/(abc)|(efg)/' temp 使用|时,语句需要括起来AND与关系:awk '{if ( $1=="a" && $2=="b" )print $0}' tempOR或关系:awk '{if ($1=="a" || $1=="b") print $0}' temp二、awk内置变量:ARGC 命令行参数个数AGRV 命令行参数排列ENVIRON 支持队列中系统环境变量的使用FILENAME awk浏览的文件名FNR 浏览文件的记录数FS 设置输入域分隔符,同- F选项NF 浏览记录的域个数NR 已读的记录数OFS 输出域分隔符ORS 输出记录分隔符RS 控制记录分隔符例:awk 'END {print NR}'temp 在最后打印已读记录条数awk '{print NF,NR,$0} END {print FILENAME}' tempawk '{if (NR>0 &&$4~/Brown/) print $0}' temp 至少存在一条记录且包含BrownNF的另一用法:echo $PWD | awk -F/ '{print$NF}' 显示当前目录名awk操作符:在awk中使用操作符,基本表达式可以划分成数字型、字符串型、变量型、域及数组元素设置输入域到变量名:awk'{name=$1;six=$3; if (six=="man") print name " is " six}'temp域值比较操作:awk 'BEGIN{BASE="27"} {if ($4<BASE) print $0}' temp修改数值域取值:(原输入文件不会被改变)awk '{if ($1=="asima")$6=$6-1;print $1,$6,$7}' temp修改文本域:awk '{if ($1=="asima) ($1=="desc");print $1}' temp只显示修改记录:(只显示所需要的,区别上一条命令,注意{})awk '{if ($1=="asima) {$1=="desc";print$1}}'temp创建新的输出域:awk '{$4=$3-$2; print $4}' temp统计列值:awk '(tot+=$3);END {print tot}'temp 会显示每列的内容awk '{(tot+=$3)};END {printtot}'temp 只显示最后的结果文件长度相加:ls -l|awk '/^[^d]/ {print$9"\t"$5} {tot+=$5} END{print "totKB:" tot}'只列出文件名:ls -l|awk'{print$9}' 常规情况文件名是第9域awk内置字符串函数:gsub(r,s)在整个$0中用s替代rawk'gsub(/name/,"xingming") {print $0}' tempgsub(r,s,t)在整个t中用s替代rindex(s,t)返回s中字符串t的第一位置awk 'BEGIN{print index("Sunny","ny")}'temp 返回4length(s)返回s的长度match(s,r)测试s是否包含匹配r的字符串awk'$1=="J.Lulu" {print match($1,"u")}'temp 返回4split(s,a,fs)在fs上将s分成序列aawk 'BEGIN{print split("12#345#6789",myarray,"#")"'返回3,同时myarray[1]="12", myarray[2]="345",myarray[3]="6789"sprint(fmt,exp)返回经fmt格式化后的expsub(r,s)从$0中最左边最长的子串中用s代替r(只更换第一遇到的匹配字符串)substr(s,p)返回字符串s中从p开始的后缀部分substr(s,p,n)返回字符串s中从p开始长度为n的后缀部分printf函数的使用:字符转换:echo "65" |awk '{printf"%c\n",$0}' 输出Aawk 'BEGIN {printf"%f\n",999}' 输出999.000000格式化输出:awk'{printf "%-15s %s\n",$1,$3}' temp 将第一个域全部左对齐显示其他awk用法:向一行awk命令传值:awk '{if ($5<AGE) print $0}' AGE=10 tempwho | awk '{if ($1==user) print $1 " are in " $2 ' user=$LOGNAME使用环境变量awk脚本命令:开头使用 !/bin/awk -f ,如果没有这句话自含脚本将不能执行,例子:1.!/bin/awk-f2.# allcomment lines must start with a hash '#'3.#name: student_tot.awk4.# tocall: student_tot.awk grade.txt5.#prints total and average of club student points6.7.#print a header first8.BEGIN9.{10.print"Student Date Member No. Grade AgePoints Max"11.print"Name Joined Gained Point Available"12.print"=============================== =================================="13.}14.#let's add the scores of points gained15.(tot+=$6);16.#finished processing now let's print the total and averagepoint17.END18.{19.print "Club student total points :" tot20.print "Average Club Student points :" tot/N21.}[plain] view plaincopyprint?1.awk数组:awk的循环基本结构 For (element in array) print array[element]awk'BEGIN{record="123#456#789";split(record,myarray,"#")} END { for (i in myarray) {print myarray[i]} }[html] view plaincopyprint?1.awk -v MASS_UNPLUG=$MASS_UNPLUG '2.{3.<PRE class=html name="code"><SPAN style="WHITE-SPACE: pre"></SPAN>if ($0 ~ /^\/dev\/sd/) {4.<SPAN style="WHITE-SPACE: pre"></SPAN>print "umount " $2;5.<SPAN style="WHITE-SPACE: pre"></SPAN>if (system("umount " $2)) {6.<SPAN style="WHITE-SPACE: pre"></SPAN>print "umount fail!";7.<SPAN style="WHITE-SPACE: pre"></SPAN>if ($2 ~ /nand/) {8.<SPAN style="WHITE-SPACE: pre"></SPAN>if (plug_devs) {9.<SPAN style="WHITE-SPACE: pre"></SPAN>plug_devs = plug_devs " /dev/ null";10.<SPAN style="WHITE-SPACE: pre"></SPAN>} else {11.<SPAN style="WHITE-SPACE: pre"></SPAN>plug_devs = "/dev/null";12.<SPAN style="WHITE-SPACE: pre"></SPAN>}13.<SPAN style="WHITE-SPACE: pre"></SPAN>}14.<SPAN style="WHITE-SPACE: pre"></SPAN>}15.<SPAN style="WHITE-SPACE: pre"></SPAN>}</PRE>}END {system("echo \"/usr/mas s /dev/null&\" >> " MASS_UNPLUG);print "/usr/mass " plug_de vs " &";system("/usr/mass " plug_devs " &");} ' /proc/mounts<P ></P>16.<PRE></PRE>17.<BR>18.上面是我遇到的一个AWK的样例:19.<P></P>20.<P>功能就是:查找/proc/mount 文件中记录的一些挂载节点数据!</P>21.<P><BR>22.</P>23.<P></P>24.<BR>。
awk命令用法
awk命令⽤法 awk:把⽂件逐⾏的读⼊,以空格为默认分隔符将每⾏切⽚,切开的部分再进⾏各种分析处理,是⼀个强⼤的⽂本分析⼯具,在对数据分析并⽣成报告时很有优势。
awk有3个不同版本: awk、nawk和gawk,未作特别说明,⼀般指gawk,gawk 是 AWK 的 GNU 版本。
命令格式:awk [options] 'program' FILE ...其中:options:-F:指明输⼊时⽤到的字段分隔符,默认空⽩字符;-v:指定变量-v var=value:⾃定义变量program:PATTERN{ ACTION STATEMENTS;...} (语句之间⽤ ; 分隔)PATTERN--模式,这意味着并不是对⽂件中的每⼀⾏进⾏处理,⽽是处理那些能够被模式匹配到的⾏,不跟模式表⽰全⽂;ACTION--常见的处理机制是打印,命令有print和printf.变量常见内置变量 FS:切割时的分隔符,默认为空⽩字符; OFS:切割后输出时的分隔符,默认为空⽩字符; RS:输⼊时的换⾏符,默认为'\n'; ORS:输出时的换⾏符,默认为'\n'; NF:字段数量 ( $NF表⽰最后⼀个字段); NR:⾏数; FNR:分别计算各⽂件的⾏数; FILENAME:当前⽂件名; ARGC:命令⾏参数的个数; ARGV:数组,保存的是命令⾏所给定的各参数⽰例:awk -v FS=: '{print $1}' /etc/passwd (相当于awk -F: "{print $1}" /etc/passwd)awk -v FS=: -v OFS=, '{print $1,$2}' /etc/passwdawk -v RS=' ' '{print}' /etc/issueawk '{print NF}' /etc/fstab (可对⽐ awk '{print $NF}' /etc/fstab,$NF表⽰最后⼀个字段)awk 'BEGIN{print ARGC}' /etc/fstab /etc/issue (命令⾏参数有3个,分别为awk,/etc/fstab,/etc/issue)awk 'BEGIN{print ARGV[#]}' /etc/fstab /etc/issue (#表⽰索引下标)⾃定义变量两种⽅式可⾃定义变量:(1) -v var=value(2) 在program中直接定义⽰例: awk -v test="hello gawk" 'BEGIN{print test}' (相当于awk 'BEGIN{test="hello gawk";print test}')打印输出printprint item1,item2,...⽰例:tail -5 /etc/fstab | awk '{print $2,$4}' ($1..$#:内置变量,表⽰分隔后的字段)tail -5 /etc/fstab | awk '{print "hello:",$2,$4}' (注意,{}只能由单引号'' 引起来,不能⽤双引号"")要点:(1) 逗号,作为不同字段的分隔符;(2) item可以是字符串,数值,当前记录的字段、变量或awk的表达式;(3) 如省略item,相当于print $0(打印所有元素;$0表⽰所有字段)printf格式化输出:printf FORMAT,item1,item2,...释义:(1) FORMAT必须给出;(2) 不会⾃动换⾏,需要显式给出换⾏控制符,'\n';(3) FORMAT中需要分别为后⾯的每个item指定⼀个格式化符号;格式符:%c:显⽰字符的ASCII码;%d,%i:显⽰⼗进制整数;%e,%E:科学计数法数值显⽰;%f:显⽰为浮点数;%g,%G:以科学计数法或浮点形式显⽰数值;%s:显⽰字符串;%u:⽆符号整数;%%:显⽰%⾃⾝修饰符:#[.#]:第⼀个数字控制显⽰的宽度;第⼆个#表⽰⼩数点后的精度⽰例: %-3.1f,其中 '-' 表⽰左对齐;%+5.2d,其中 '+' 会显⽰数值的符号 awk -F: '{printf "Uername:%s, UID:%d\n",$1,$3}' /etc/passwd awk -F: '{printf "Uername:%-15s, UID:%d\n",$1,$3}' /etc/passwd操作符 算术操作符:x+y,x-y,x*y,x/y,x^y(多少次⽅),x%y 赋值操作符:=,+=,-=,*=,/=,%=,^=,++,-- ⽐较操作符:>,>=,<,<=,!=,== 模式匹配符:~:是否匹配;!~:是否不匹配 逻辑操作符:&&,||,! 函数调⽤:function_name(argu1,argu2,...) 条件表达式:selector ? if-true-expression : if-false-expression⽰例: awk -F: '{$3>=1000?usertype="Common User":usertype="Sysadmin or SysUser";printf "%15s : %-s\n",$1,usertype}' /etc/passwd awk '!/^UUID/{print $0}' /etc/fstab awk -F: '$3>1000{print $1,$3}' /etc/passwd awk -F: '$NF~/bash$/{print $1,$NF}' /etc/passwdPATTERN(1) /regular expression/:仅处理被模式匹配到的⾏;(2) relational expression:关系表达式,为"真"时处理 ("真":结果是⾮0值或⾮空字符串);(3) line ranges:⾏范围 (startline, endline 或 /pat1/, /pat2/);注意:此处⾏范围不⽀持直接给出数字的格式⽰例: awk -F: '(NR>=2&&NR<=10){print $1}' /etc/passwd awk -F: '/^h/,/^s/{print $1}' /etc/passwd(4) BEGIN/END模式:BEGIN{}: 仅在开始处理⽂件中的⽂本之前执⾏⼀次;END{}:仅在⽂本处理完成之后执⾏⼀次⽰例: head /etc/passwd | awk -F: 'BEGIN{print "username uid"}{printf "%-12s%-5s\n",$1,$3}END{printf "%10s\n","END"}'控制语句if-else语法:if(condition) statement [else statement]使⽤场景:对awk取得的整⾏或某个字段做条件判断.⽰例:awk -F: '{if($3>=1000) {printf "Common user: %s\n",$1} else {printf "root or Sysuser: %s\n",$1}}' /etc/passwdawk -F: '{if($NF=="/bin/bash") print $1}' /etc/passwdawk '{if(NF>5) print $0}' /etc/fstabdf -h | awk -F% '/^\/dev/{print $1}' | awk '{if($NF>=20) print $1}'while and do while语法:while(condition) statement (条件"真"时进⼊循环;条件"假"时退出循环)do statement while(condition) (⾄少执⾏⼀次循环体)使⽤场景:对⼀⾏内的多个字段逐⼀处理时使⽤;对数组中的各元素逐⼀处理时使⽤.⽰例:awk '/^[[:space:]]*linux16/{i=1;while(i<=NF) {print $i,length($i); i++}}' /etc/grub2.cfgawk '/^[[:space:]]*linux16/{i=1;while(i<=NF) {if(length($i)>=7) {print $i,length($i)}; i++}}' /etc/grub2.cfgfor语法:for(expr1;expr2;expr3) statementfor(variable assignment;condition;iteration process) {for-body}⽰例:awk '/^[[:space:]]*linux16/{for(i=1;i<=NF;i++) {print $i,length($i)}}' /etc/grub2.cfg特殊⽤法:遍历数组中的元素语法:for(var in array) {for-body}switch语法:switch(expression) {case VALUE1 or /REGEXP/: statement; case VALUE2 or /REGEXP2/: statement; ...; default: statement} break and continuebreak:终⽌循环continue:中断本次循环继续下⼀轮next提前结束对本⾏的处理⽽直接进⼊下⼀⾏;⽰例:awk -F: '{if($3%2!=0) next; print $1,$3}' /etc/passwdarray数组1) 关联数组:array[index-expression]index-expression:①可使⽤任意字符串;字符串要使⽤双引号;②如果某数组元素事先不存在,在引⽤时,awk会⾃动创建此元素,并将其值初始化为"空串"2) 若要判断数组中是否存在某元素,要使⽤"index in array"格式进⾏;3) 若要遍历数组中的每个元素,要使⽤for循环:for(var in array) {for-body}⽰例:awk 'BEGIN{weekdays["mon"]="Monday";weekdays["tue"]="Tuesday";for(i in weekdays) {print weekdays[i]}}' netstat -tan | awk '/^tcp\>/{state[$NF]++}END{for(i in state){ print i,state[i]}}'awk '{ip[$1]++}END{for(i in ip){print i,ip[i]}}' /var/log/httpd/access_logawk '/^UUID/{fs[$3]++}END{for(i in fs){print i,fs[i]}}' /etc/fstabawk '{for(i=1;i<=NF;i++){count[$i]++}}END{for(i in count){print i,count[i]}}' /etc/fstabnetstat -tan | awk '/^tcp\>/{state[$NF]++}END{for(i in state){print i,state[i]}}'内置函数rand():返回0和1之间⼀个随机数;length([s]):返回指定字符串的长度;sub(r,s,[t]):以r表⽰的模式来查找t所表⽰的字符中的匹配的内容,并将其第⼀次出现替换为s所表⽰的内容; gsub(r,s,[t]):以r表⽰的模式来查找t所表⽰的字符中的匹配的内容,并将其所有出现均替换为s所表⽰的内容; split(s,a,[r]):以r为分隔符切割字符s,并将切割后的结果保存⾄a所表⽰的数组中⽰例:netstat -tan | awk '/^tcp\>/{split($5,ip,":");count[ip[1]]++}END{for(i in count){print i,count[i]}}'awk '/^[[:space:]]*kernel/{i=1;while(i<=NF){if(length($i)>=7)print $i,length($i);i++}}' /etc/grub.conf。
Moxa AWK-1137C Series 产品说明书
AWK-1137C SeriesIndustrial802.11a/b/g/n wireless clientFeatures and Benefits•IEEE802.11a/b/g/n compliant client•Comprehensive interfaces with one serial port and two Ethernet LAN ports•Millisecond-level Client-based Turbo Roaming1•2x2MIMO future-proof technology•Integrated robust antenna and power isolation•Anti-vibration design•Compact size for your industrial applications•Easy setup and deployment with AeroMagCertificationsIntroductionThe AWK-1137C is an ideal client solution for industrial wireless mobile applications.It enables WLAN connections for both Ethernet and serial devices,and is compliant with industrial standards and approvals covering operating temperature,power input voltage,surge,ESD,and vibration. The AWK-1137C can operate on either the2.4or5GHz bands,and is backwards-compatible with existing802.11a/b/g deployments to future-proof your wireless investments.Industrial Ruggedness•Integrated antenna and power isolation designed to provide500V insulation protection against external electrical interference•-40to75°C wide operating temperature models(-T)available for smooth wireless communication in harsh environmentsMobility-oriented Design•Client-based Turbo Roaming1for<150ms roaming recovery time between APs•MIMO technology to ensure transmitting and receiving capability while on the move•Anti-vibration performance(with reference to IEC60068-2-6)Easy Integration•Semi-automatically configurable to reduce deployment cost•AeroMag support for error-free setup of your industrial applications’basic WLAN settings•Various communication interfaces for connecting to different types of devices•One-to-many NAT to simplify your machine setupSpecificationsWLAN InterfaceWLAN Standards802.11a/b/g/n802.11i Wireless SecurityModulation Type DSSSOFDMMIMO-OFDMFrequency Band for US(20MHz operating channels) 2.412to2.462GHz(11channels)5.180to5.240GHz(4channels)5.260to5.320GHz(4channels)21.The Turbo Roaming recovery time indicated herein is an average of test results documented,in optimized conditions,across APs configured with interference-free20-MHz RF channels,WPA2-PSK security,and default Turbo Roaming parameters.The clients are configured with3-channel roaming at100Kbps traffic load.Other conditions may also impact roaming performance.For more information about Turbo Roaming parameter settings,refer to the product manual.5.500to5.700GHz(11channels)35.745to5.825GHz(5channels)Frequency Band for EU(20MHz operating channels) 2.412to2.472GHz(13channels)5.180to5.240GHz(4channels)5.260to5.320GHz(4channels)35.500to5.700GHz(11channels)3Frequency Band for JP(20MHz operating channels) 2.412to2.484GHz(14channels)5.180to5.240GHz(4channels)5.260to5.320GHz(4channels)35.500to5.700GHz(11channels)3Wireless Security WEP encryption(64-bit and128-bit)WPA/WPA2-Enterprise(IEEE802.1X/RADIUS,TKIP,AES)WPA/WPA2-PersonalTransmission Rate802.11b:1to11Mbps802.11a/g:6to54Mbps802.11n:6.5to300MbpsTransmitter Power for802.11a23±1.5dBm@6to24Mbps21±1.5dBm@36Mbps20±1.5dBm@48Mbps18±1.5dBm@54MbpsTransmitter Power for802.11n(5GHz)23±1.5dBm@MCS0/820MHz18±1.5dBm@MCS7/1520MHz23±1.5dBm@MCS0/840MHz18±1.5dBm@MCS7/1540MHzTransmitter Power for802.11b26±1.5dBm@1Mbps26±1.5dBm@2Mbps26±1.5dBm@5.5Mbps25±1.5dBm@11MbpsTransmitter Power for802.11g23±1.5dBm@6to24Mbps22±1.5dBm@36Mbps20±1.5dBm@48Mbps19±1.5dBm@54MbpsTransmitter Power for802.11n(2.4GHz)23±1.5dBm@MCS0/820MHz17±1.5dBm@MCS7/1520MHz23±1.5dBm@MCS0/840MHz17±1.5dBm@MCS7/1540MHzTransmitter Power2.4GHz26dBm18dBm18dBm5GHz(UNII-1)23dBm23dBm23dBm5GHz(UNII-2)23dBm23dBm23dBm5GHz(UNII-2e)23dBm23dBm23dBm5GHz(UNII-3)23dBm––Note:Based on regional regulations,the maximum transmission power allowed onthe UNII bands is restricted in the firmware,as indicated above.Receiver Sensitivity for802.11a(measured at5.680 GHz)Typ.-90@6Mbps Typ.-88@9Mbps Typ.-87@12Mbps Typ.-85@18Mbps Typ.-81@24Mbps Typ.-78@36Mbps Typ.-74@48MbpsTyp.-73@54Mbps Note4Receiver Sensitivity for802.11n(5GHz;measured at 5.680GHz)Typ.-69dBm@MCS720MHz Typ.-70dBm@MCS1520MHz Typ.-64dBm@MCS740MHz Typ.-66dBm@MCS1540MHz Note4Receiver Sensitivity for802.11b(measured at2.437 GHz)Typ.-89dBm@1Mbps Typ.-89dBm@2Mbps Typ.-89dBm@5.5Mbps Typ.-88dBm@11MbpsReceiver Sensitivity for802.11g(measured at2.437 GHz)Typ.-88dBm@6Mbps Typ.-88dBm@9Mbps Typ.-88dBm@12Mbps Typ.-87dBm@18Mbps Typ.-84dBm@24Mbps Typ.-81dBm@36Mbps Typ.-77dBm@48Mbps Typ.-75dBm@54MbpsReceiver Sensitivity for802.11n(2.4GHz;measured at2.437GHz)Typ.-70dBm@MCS720MHz Typ.-70dBm@MCS1520MHz Typ.-64dBm@MCS740MHz Typ.-65dBm@MCS1540MHzWLAN Operation Mode Client,Client-Router,Slave,SnifferAntenna External,2/2dBi,Omni-directionalAntenna Connectors2RP-SMA femaleEthernet Interface10/100BaseT(X)Ports(RJ45connector)2Standards IEEE802.3for10BaseTIEEE802.3u for100BaseT(X)IEEE802.1Q for VLAN TaggingEthernet Software FeaturesManagement DHCP Server/Client,HTTP,IPv4,LLDP,SMTP,SNMPv1/v2c/v3,Syslog,TCP/IP,Telnet,UDP,Proxy ARP,VLAN,Wireless Search Utility,MXview,MXconfigSecurity HTTPS/SSL,RADIUS,SSHTime Management NTP Client,SNTP ClientFirewallFilter ICMP,MAC address,IP protocol,Port-basedSerial InterfaceConnector DB9maleSerial Standards RS-232,RS-422/485,RS-232/422/485Operation Modes Disabled,Real COM,RFC2217,TCP Client,TCP Server,UDPData Bits5,6,7,8Stop Bits1,1.5,2Parity None,Even,Odd,Space,MarkFlow Control None,RTS/CTS,XON/XOFFBaudrate75bps to921.6kbpsSerial Data Log256KBSerial SignalsRS-232TxD,RxD,RTS,CTS,DCD,GND,DTR,DSRRS-422Tx+,Tx-,Rx+,Rx-,GNDRS-485-2w Data+,Data-,GNDRS-485-4w Tx+,Tx-,Rx+,Rx-,GNDLED InterfaceLED Indicators SYS,LAN1,LAN2,WLAN,SerialInput/Output InterfaceButtons Reset buttonPhysical CharacteristicsHousing MetalIP Rating IP30Dimensions77.1x115.5x26mm(3.04x4.55x1.02in)Weight470g(1.03lb)Installation DIN-rail mounting,Wall mounting(with optional kit)Power ParametersInput Voltage9to30VDCPower Connector1removable3-contact terminal block(s)Power Consumption11.7W(max.)Reverse Polarity Protection SupportedEnvironmental LimitsOperating Temperature Standard Models:0to60°C(32to140°F)Wide Temp.Models:-40to75°C(-40to167°F)Storage Temperature(package included)-40to85°C(-40to185°F)Ambient Relative Humidity5to95%(non-condensing)Standards and CertificationsEMC EN61000-6-2/-6-4,EN55032/24EMI CISPR22,FCC Part15B Class AEMS IEC61000-4-2ESD:Contact:8kV;Air:15kVIEC61000-4-3RS:80MHz to1GHz:10V/mIEC61000-4-4EFT:Power:2kV;Signal:1kVIEC61000-4-5Surge:Power:2kV;Signal:1kVIEC61000-4-6CS:10VIEC61000-4-8PFMFRadio EN300328,EN301489-1/17,EN301893,FCC ID SLE-1137C,ANATEL,MIC,NCC,Road Vehicles E mark E1Safety EN60950-1,UL60950-1Vibration IEC60068-2-6MTBFTime1,125,942hrsStandards Telcordia SR332WarrantyWarranty Period5yearsDetails See /warranty Package ContentsDevice1x AWK-1137C Series wireless client Installation Kit1x DIN-rail kitAntenna2x2.4/5GHz antenna Documentation1x quick installation guide1x warranty card DimensionsOrdering InformationAWK-1137C-EU EU802.11a/b/g/n0to60°C AWK-1137C-EU-T EU802.11a/b/g/n-40to75°C AWK-1137C-JP JP802.11a/b/g/n0to60°C AWK-1137C-JP-T JP802.11a/b/g/n-40to75°C AWK-1137C-US US802.11a/b/g/n0to60°C AWK-1137C-US-T US802.11a/b/g/n-40to75°C Accessories(sold separately)AntennasANT-WDB-ANF-0407 2.4/5GHz,omni-directional antenna,4/7dBi,N-type(male)ANT-WDB-ANF-0609 2.4/5GHz,omni-directional antenna,6/9dBi,N-type(female)ANT-WDB-ANM-0306 2.4/5GHz,omni-directional antenna,3/6dBi,N-type(male)ANT-WDB-ANM-0407 2.4/5GHz,dual-band omni-directional antenna,4/7dBi,N-type(male)ANT-WDB-ANM-0502 2.4/5GHz,omni-directional antenna,5/2dBi,N-type(male)ANT-WDB-ANM-0609 2.4/5GHz,omni-directional antenna,6/9dBi,N-type(male)ANT-WDB-ARM-02 2.4/5GHz,omni-directional rubber duck antenna,2dBi,RP-SMA(male)ANT-WDB-ARM-0202 2.4/5GHz,panel antenna,2/2dBi,RP-SMA(male)ANT-WDB-PNF-1518 2.4/5GHz,panel antenna,15/18dBi,N-type(female)MAT-WDB-CA-RM-2-0205 2.4/5GHz,ceiling antenna,2/5dBi,MIMO2x2,RP-SMA-type(male)MAT-WDB-DA-RM-2-0203-1m 2.4/5GHz,desktop antenna,2/3dBi,MIMO2x2,RP-SMA-type(male),1m cableMAT-WDB-PA-NF-2-0708 2.4/5GHz,panel antenna,7/8dBi,MIMO2x2,N-type(female)ANT-WSB5-ANF-125GHz,omni-directional antenna,12dBi,N-type(female)ANT-WSB5-PNF-185GHz,directional panel antenna,18dBi,N-type(female)ANT-WSB-ANF-09 2.4GHz,omni-directional antenna,9dBi,N-type(female)ANT-WSB-PNF-12 2.4GHz,directional panel antenna,12dBi,N-type(female)ANT-WSB-PNF-18 2.4GHz,directional panel antenna,18dBi,N-type(female)ANT-WSB-AHRM-05-1.5m 2.4GHz,omni-directional/dipole antenna,5dBi,RP-SMA(male),1.5m cableWireless Antenna CablesA-CRF-RFRM-S2-60SS402cable,RP-SMA(male)to RP-SMA(female)A-CRF-RFRM-R4-150RF magnetic stand,RP-SMA(male)to RP-SMA(female),RG-174/U cable,1.5mA-CRF-RMNM-L1-300N-type(male)to RP SMA(male),LMR-195Lite cable,3mA-CRF-RMNM-L1-600N-type(male)to RP SMA(male),LMR-195Lite cable,6mA-CRF-RMNM-L1-900N-type(male)to RP SMA(male),LMR-195Lite cable,9mCRF-N0117SA-3M N-type(male)to RP SMA(male),CFD200cable,3mSurge ArrestorsA-SA-NFNF-01Surge arrestor,N-type(female)to N-type(female)A-SA-NMNF-01Surge arrester,N-type(female)to N-type(male)Wireless AdaptersWireless Terminating ResistorsA-TRM-50-NM Terminating Resistor,50ohm,RP-SMA MaleWall-Mounting KitsWK-35-01Wall-mounting kit,2plates,6screws,35x44x2.5mm©Moxa Inc.All rights reserved.Updated Sep05,2019.This document and any portion thereof may not be reproduced or used in any manner whatsoever without the express written permission of Moxa Inc.Product specifications subject to change without notice.Visit our website for the most up-to-date product information.。
Unix awk使用手册
™– ˜u e>˜Þ_Ã`Å b v…FLASH b 爱电脑 Y}_Ã`ÅBBS给我留言认识版主unix awkO•u(bK册O\€ v…话:《unix awkO•u(bK册》是我几个月前的作品了,回过头来看,这篇文章实在是很粗燥,因当时我写作并上传这个作品时实在是太忙了,没有对文章的质量进行很好的检查,心里老觉得有愧于网友的厚爱,于是趁闲赶忙重写一遍,虽然不一定会有很大的改观,但质量是肯定要好一点的,唯如此,我的良心上才好受一点,呶,下面就是我的修改稿,各位老友请与第一版相比一下,看是否有所进步!这次改写仍然保留了原有的风格:正文由浅入深,文后附上了大量的相关资料,这样做的原因是为了满足各种用户的需求,这在第一版中已经说过了。
这次主要的改变是在内容上,加入了很多新内容,并增加了示例,以帮助读者理解其中的内容,附录也补充了许多新的资料。
当然读者要真正地掌握awkÿ 仅仅读了本文是不够的,还必须有上机实习这一步。
值得提醒大家的是,awkg _ˆY r Hg,ÿ ^vN T N*rHg,NK•ô[XW(w@N N›]î别,因此,在使用awkNåRMg Y}S€ N N O`O•u(v…|û~ßv…€Tg:^.R©0NÀNHf/awk?O`Sï€ý对unixkÔ较熟悉,但你可能对awk_ˆ–Lu ÿ这一点也不奇怪,的确,与其优秀的功能相比,awk还远没达到它应有的知名度。
awkf/NÀNHÿ N Q v[ƒY'Y 数unixT}NäN T v…f/ÿ NÎT [WN wÿb们不可能知道awkv…RŸ€ýÿ [ƒeâN f/Qwg 独立意义的英文单词,也不是几个相关单词的缩写。
Moxa AWK-1131A 产品说明书
AWK-1131A SeriesEntry-level industrial IEEE802.11a/b/g/n wireless AP/clientFeatures and Benefits•IEEE802.11a/b/g/n AP/client support•Millisecond-level Client-based Turbo Roaming1•Integrated antenna and power isolation•5GHz DFS channel supportCertificationsIntroductionThe AWK-1131A industrial wireless AP/client meets the growing need for faster data transmission speeds by supporting IEEE802.11n technology with a net data rate of up to300Mbps.The AWK-1131A is compliant with industrial standards and approvals covering operating temperature, power input voltage,surge,ESD,and vibration.The two redundant DC power inputs increase the reliability of the power supply.The AWK-1131A can operate on either the2.4or5GHz bands and is backwards-compatible with existing802.11a/b/g deployments to future-proof your wireless investments.The Wireless add-on for the MXview network management utility visualizes the AWK's invisible wireless connections to ensure wall-to-wall Wi-Fi connectivity.Improved Higher Data Rate and Channel Capacity•High-speed wireless connectivity with up to300Mbps data rate•MIMO technology to improve the capability of transmitting and receiving multiple data streams•Increased channel width with channel bonding technology•Supports flexible channel selection to build up wireless communication system with DFSSpecifications for Industrial-grade Applications•Redundant DC power inputs•Integrated isolation design with enhanced protection against environmental interference•Compact aluminum housing,IP30-ratedWireless Network Management With MXview Wireless•Dynamic topology view shows the status of wireless links and connection changes at a glance•Visual,interactive roaming playback function to review the roaming history of clients•Detailed device information and performance indicator charts for individual AP and client devicesSpecificationsWLAN InterfaceWLAN Standards802.11a/b/g/n802.11i Wireless SecurityModulation Type DSSSOFDMMIMO-OFDMFrequency Band for US(20MHz operating channels) 2.412to2.462GHz(11channels)5.180to5.240GHz(4channels)1.The Turbo Roaming recovery time indicated herein is an average of test results documented,in optimized conditions,across APs configured with interference-free20-MHz RF channels,WPA2-PSK security,and default Turbo Roaming parameters.The clients are configured with3-channel roaming at100Kbps traffic load.Other conditions may also impact roaming performance.For more information about Turbo Roaming parameter settings,refer to the product manual.5.260to5.320GHz(4channels)25.500to5.700GHz(11channels)25.745to5.825GHz(5channels)Frequency Band for EU(20MHz operating channels) 2.412to2.472GHz(13channels)5.180to5.240GHz(4channels)5.260to5.320GHz(4channels)25.500to5.700GHz(11channels)2Frequency Band for JP(20MHz operating channels) 2.412to2.484GHz(14channels)5.180to5.240GHz(4channels)5.260to5.320GHz(4channels)25.500to5.700GHz(11channels)2Wireless Security WEP encryption(64-bit and128-bit)WPA/WPA2-Enterprise(IEEE802.1X/RADIUS,TKIP,AES)WPA/WPA2-PersonalTransmission Rate802.11b:1to11Mbps802.11a/g:6to54Mbps802.11n:6.5to300MbpsTransmitter Power for802.11a23±1.5dBm@6to24Mbps21±1.5dBm@36Mbps20±1.5dBm@48Mbps18±1.5dBm@54MbpsTransmitter Power for802.11n(5GHz)23±1.5dBm@MCS0/820MHz18±1.5dBm@MCS7/1520MHz23±1.5dBm@MCS0/840MHz17±1.5dBm@MCS7/1540MHzTransmitter Power for802.11b26±1.5dBm@1Mbps26±1.5dBm@2Mbps26±1.5dBm@5.5Mbps25±1.5dBm@11MbpsTransmitter Power for802.11g23±1.5dBm@6to24Mbps21±1.5dBm@36Mbps19±1.5dBm@48Mbps18±1.5dBm@54MbpsTransmitter Power for802.11n(2.4GHz)23±1.5dBm@MCS0/820MHz18±1.5dBm@MCS7/1520MHz23±1.5dBm@MCS0/840MHz17±1.5dBm@MCS7/1540MHzTransmitter Power2.4GHz26dBm18dBm18dBm5GHz(UNII-1)23dBm21dBm21dBm5GHz(UNII-2)23dBm21dBm21dBm5GHz(UNII-2e)23dBm23dBm23dBm5GHz(UNII-3)23dBm––Note:Based on regional regulations,the maximum transmission power allowed onthe UNII bands is restricted in the firmware,as indicated above.Receiver Sensitivity for802.11a(measured at5.680 GHz)Typ.-90@6Mbps Typ.-88@9Mbps Typ.-88@12Mbps Typ.-85@18Mbps Typ.-81@24Mbps Typ.-78@36Mbps2.DFS(Dynamic Frequency Selection)channel support:In AP mode,when a radar signal is detected,the device will automatically switch to another channel.However,according to regulations,after switching channels,a60-second availability check period is required before starting the service.Typ.-74@48MbpsTyp.-72@54MbpsNote:Due to a limitation in the receiver sensitivity performance for channels153and 161,it is recommended to avoid using these channels in your critical applications.Receiver Sensitivity for802.11n(5GHz;measured at 5.680GHz)Typ.-69dBm@MCS720MHzTyp.-71dBm@MCS1520MHzTyp.-63dBm@MCS740MHzTyp.-68dBm@MCS1540MHzNote:Due to a limitation in the receiver sensitivity performance for channels153and 161,it is recommended to avoid using these channels in your critical applications.Receiver Sensitivity for802.11b(measured at2.437 GHz)Typ.-93dBm@1Mbps Typ.-93dBm@2Mbps Typ.-93dBm@5.5Mbps Typ.-88dBm@11MbpsReceiver Sensitivity for802.11g(measured at2.437 GHz)Typ.-88dBm@6Mbps Typ.-86dBm@9Mbps Typ.-85dBm@12Mbps Typ.-85dBm@18Mbps Typ.-85dBm@24Mbps Typ.-82dBm@36Mbps Typ.-78dBm@48Mbps Typ.-74dBm@54MbpsReceiver Sensitivity for802.11n(2.4GHz;measured at2.437GHz)Typ.-70dBm@MCS720MHz Typ.-69dBm@MCS1520MHz Typ.-67dBm@MCS740MHz Typ.-67dBm@MCS1540MHzWLAN Operation Mode Access point,Client,SnifferAntenna External,2/2dBi,Omni-directionalAntenna Connectors2RP-SMA femaleEthernet InterfaceStandards IEEE802.3for10BaseTIEEE802.3u for100BaseT(X)IEEE802.3ab for1000BaseT(X)IEEE802.1X for authentication10/100/1000BaseT(X)Ports(RJ45connector)1Ethernet Software FeaturesManagement DHCP Server/Client,DNS,HTTP,IPv4,LLDP,Proxy ARP,SMTP,SNMPv1/v2c/v3,Syslog,TCP/IP,Telnet,UDP,VLAN,Wireless Search Utility,MXview,MXview Wireless,MXconfigSecurity HTTPS/SSL,RADIUS,SSHTime Management SNTP ClientFirewallFilter ICMP,MAC address,IP protocol,Port-basedSerial InterfaceConsole Port RS-232,8-pin RJ45LED InterfaceLED Indicators PWR,FAULT,STATE,SIGNAL,WLAN,LANInput/Output InterfaceButtons Reset buttonPhysical CharacteristicsHousing MetalIP Rating IP30Dimensions58x115x70mm(2.29x4.53x2.76in)Weight307g(0.68lb)Installation DIN-rail mounting,Wall mounting(with optional kit)Power ParametersInput Current0.56A@12VDC,0.14A@48VDCInput Voltage12to48VDCPower Connector1removable4-contact terminal block(s)Power Consumption 6.96W(max.)Reverse Polarity Protection SupportedEnvironmental LimitsOperating Temperature Standard Models:0to60°C(32to140°F)Wide Temp.Models:-40to75°C(-40to167°F)Storage Temperature(package included)-40to85°C(-40to185°F)Ambient Relative Humidity5to95%(non-condensing)Standards and CertificationsEMC EN55032/24EMI CISPR32,FCC Part15B Class AEMS IEC61000-4-2ESD:Contact:4kV;Air:8kVIEC61000-4-3RS:80MHz to1GHz:10V/mIEC61000-4-4EFT:Power:2kV;Signal:1kVIEC61000-4-5Surge:Power:2kV;Signal:1kVIEC61000-4-6CS:3VIEC61000-4-8PFMFRadio EN300328,EN301489-1/17,EN301893,FCC ID SLE-WAPN008,MIC,NCC,RCM,SRRC,WPC,KC,RCM,ANATELSafety EN60950-1,UL60950-1Vibration IEC60068-2-6MTBFTime749,476hrsStandards Telcordia SR332WarrantyWarranty Period5yearsDetails See /warrantyPackage ContentsDevice1x AWK-1131Series wireless AP/clientInstallation Kit1x cap,plastic,for RJ45port1x DIN-rail kitAntenna2x2.4/5GHz antennaDocumentation1x quick installation guide1x warranty cardDimensionsOrdering InformationModel Name Band Standards Operating Temp. AWK-1131A-EU EU802.11a/b/g/n0to60°C AWK-1131A-EU-T EU802.11a/b/g/n-40to75°C AWK-1131A-JP JP802.11a/b/g/n0to60°C AWK-1131A-JP-T JP802.11a/b/g/n-40to75°C AWK-1131A-US US802.11a/b/g/n0to60°C AWK-1131A-US-T US802.11a/b/g/n-40to75°C Accessories(sold separately)AntennasANT-WDB-ONF-07097dBi at2.4GHz or9dBi at5GHz,N-type(female),dual-band,omnidirectional antennaANT-WDB-ANM-03063dBi at2.4GHz or6dBI at5GHz,N-type(male),omnidirectional antennaANT-WDB-ONM-070707dBi at2.4GHz and07dBi at5GHz,N-type(male),dual-band omnidirectional antennaANT-WDB-ANM-05025dBi at2.4GHz or2dBI at5GHz,N-type(male),omnidirectional antennaANT-WDB-ARM-022dBi at2.4GHz or2dBi at5GHz,RP-SMA(male)omnidirectional rubber-duck antennaANT-WDB-ARM-02022dBi at2.4GHz or2dBi at5GHz,RP-SMA(male),dual-band,omnidirectional antennaANT-WDB-PNF-101110dBi at2.4GHz and11dBi at5GHz,N-type(female),dual-band directional antennaMAT-WDB-CA-RM-2-0205 2.4/5GHz,ceiling antenna,2/5dBi,MIMO2x2,RP-SMA-type(male)MAT-WDB-DA-RM-2-0203-1m 2.4/5GHz,desktop antenna,2/3dBi,MIMO2x2,RP-SMA-type(male),1m cableMAT-WDB-PA-NF-2-0708 2.4/5GHz,panel antenna,7/8dBi,MIMO2x2,N-type(female)ANT-WSB5-PNF-1616dBi at5GHz,N-type(female),single-band directional antennaANT-WSB-PNF-12-0212dBi at2.4GHz,N-type(female),single-band directional antennaANT-WSB-AHRM-05-1.5m5dBi at2.4GHz,RP-SMA(male),omnidirectional/dipole antenna,1.5m cableWireless Antenna CablesA-CRF-RFRM-J1-60RP-SMA(male)to RP-SMA(female)with JSF-141cable,0.6mA-CRF-RFRM-R4-150RF magnetic base,RP-SMA(male)to RP-SMA(female)RG-174/U cable,1.5mA-CRF-RMNM-L1-300N-type(male)to RP SMA(male)LMR-195Lite cable,3mA-CRF-RMNM-L1-600N-type(male)to RP SMA(male)LMR-195Lite cable,6mA-CRF-RMNM-L1-900N-type(male)to RP SMA(male)LMR-195Lite cable,9mSurge ArrestorsA-SA-NFNF-020to6GHz,N-type(female)to N-type(female)surge arresterA-SA-NMNF-020to6GHz,N-type(male)to N-type(female)surge arresterWireless AdaptersA-ADP-RJ458P-DB9F-ABC01DB9female to RJ45connector for the ABC-01SeriesWireless Terminating ResistorsA-TRM-50-RM50-ohm terminating resistor with RP-SMA male connectorWall-Mounting KitsWK-51-01Wall mounting kit with2plates(51.6x67x2mm)and6screws©Moxa Inc.All rights reserved.Updated Aug17,2022.This document and any portion thereof may not be reproduced or used in any manner whatsoever without the express written permission of Moxa Inc.Product specifications subject to change without notice.Visit our website for the most up-to-date product information.。
awk的nr用法
awk的nr用法nr是awk中的一个内建变量,它表示当前处理的记录号(即行号)。
在默认情况下,记录从文件的第一行开始计数,每读取一行增加1、下面是nr用法的详细解释:1.打印指定行号的行内容:使用awk的惯用方法是打印指定行号的行内容。
可以使用pattern匹配行号并打印相应的行。
例如,要打印第5行的内容,可以使用以下命令:awk 'NR==5 {print}' file.txt2.打印指定行号范围的行内容:可以使用awk的NR来打印指定行号范围的行内容。
例如,要打印1到5行的内容,可以使用以下命令:awk 'NR>=1 && NR<=5 {print}' file.txt3.计算文件的行数:通过使用NR变量,可以方便地计算文件的行数。
例如,要计算文件file.txt的行数,可以使用以下命令:awk 'END {print NR}' file.txt4.按行号插入文本:使用awk的NR变量,可以将文本插入到指定的行号。
例如,要在第3行插入一行文本“New line”,可以使用以下命令:awk 'NR==3 {print "New line"}1' file.txt5.删除指定行号的行:可以使用awk的NR变量,删除指定行号的行。
例如,要删除第2行,可以使用以下命令:awk 'NR!=2 {print}' file.txt6.打印奇数行或偶数行:使用awk的NR变量,可以打印奇数行或偶数行。
例如,要打印奇数行,可以使用以下命令:awk 'NR%2==1 {print}' file.txt7.打印最后一行:可以使用awk的END模式,打印文件的最后一行。
例如,要打印文件的最后一行awk 'END {print}' file.txt8.计算指定列的总和:可以使用awk的NR变量,计算指定列的总和。
python awk用法(一)
python awk用法(一)Python awk使用指南Python是一种强大的编程语言,而awk是一种文本处理工具,结合Python和awk的使用可以更加高效地处理文本数据。
下面是一些常见的Python awk用法,以及它们的详细讲解。
1. 使用awk提取文本中的特定列有时候,我们需要从一段文本中提取特定列的数据。
awk命令可以方便地实现这一功能。
在Python中,我们可以使用subprocess模块来调用awk命令。
import subprocesstext = "John 25 Male\nJane 30 Female\nMike 35 Male" command = "awk '{print $1, $3}'"result = (f"echo '{text}' | {command}")print(result)上述代码会输出以下结果:John MaleJane FemaleMike Male解释说明: - 使用()函数调用awk命令,其中'{print $1, $3}'表示打印第一列和第三列的数据。
- 通过echo命令将文本传递给awk命令进行处理。
2. 在文本中查找匹配行有时候,我们需要在一段文本中查找包含特定内容的行。
awk命令可以很方便地实现这一功能。
在Python中,我们可以使用subprocess模块来调用awk命令。
import subprocesstext = "apple\nbanana\norange\nkiwi"command = "awk '/a/{print}'"result = (f"echo '{text}' | {command}")print(result)上述代码会输出以下结果:applebanana解释说明: - 使用()函数调用awk命令,其中'/a/{print}'表示匹配包含字母”a”的行,并将其打印出来。
AWK用法详解
正则表达式 正则表达式同perl中的正则表达式 例:计算文件的大小(正则式的应用)
匹配非目录文件
末尾输出 统计信息
复合模式或复合操作符用于形成复杂的逻辑操作,复杂程度取决 于编程者本人 && AND : 语句两边必须同时匹配为真。 || O R: 语句两边同时或其中一边匹配为真。 ! 非求逆 awk awk '{if($4 > 90 && $5 > 0.5) print}' '{if($4 > 90 || $5 > 0.5) print}' example.txt example.txt
提示符
域
记录
调用awk 第一种是命令行方式: awk 【-F filed-separator】 ‘commands’ input-files awk ‘BEGIN{print “Good afternoon ”} {total += $1} END{print total}’ input-file 第二种方法是将所有a w k命令插入一个文件,并使a w k程序 可执行,然后用a w k命令解释器作为脚本的首行,以便通过 键入脚本名称来调用它。 chmod u+x print.awk ./print.awk input-file 第三种方式是将所有的a w k命令插入一个单独文件,然后调 用: awk –f print.awk input-file
报告头
信息尾
BEGIN和END BEGIN和END部分在awk中都仅执行一次且有各自的用途 如BEGIN用在程序一开始时, 改变awk切割字段的方式、程序一开始时, 改 变awk分隔数据行的方式、设定变量的起始值、印出一行 title、不需要 读入任何数据行,而END用来打印结尾信息或者用来输出统计信息等 awk ‘{total+=$6} END{print total}’ *.single >single awk '{total+=$6} END{print total}' *.soap >soap awk 'BEGIN{total=100} {total += $5} END{print "total:",total}' example.txt
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
awk 手册简体中文版由bones7456 (bones7456@)整理.原文:应该是.tw/aspac/reports/94/94011/但是原文很乱.说明:之前也是对awk几乎一无所知,无意中看到这篇文章,网上一搜,居然没有像样的简体中文版.有的也是不怎么完整,或者错误一大堆的.于是就顺手整理了下这篇文章.通过整理这篇文章,自己也渐渐掌握了awk的种种用法.原文可能比较老,有些目前已经不适用的命令有所改动,文中所有命令均在ubuntu7.04下调试通过,用的awk是mawk.由于本人能力有限,错误和不妥之处在所难免,欢迎多多指正.1.前言有关本手册:这是一本awk学习指引, 其重点着重于:●awk 适于解决哪些问题?●awk 常见的解题模式为何?为使读者快速掌握awk解题的模式及特性, 本手册系由一些较具代表性的范例及其题解所构成; 各范例由浅入深, 彼此间相互连贯,范例中并对所使用的awk语法及指令辅以必要的说明. 有关awk的指令, 函数,...等条列式的说明则收录于附录中, 以利读者往后撰写程序时查阅. 如此编排, 可让读者在短时间内顺畅地学会使用awk来解决问题. 建议读者循着范例上机实习, 以加深学习效果.读者宜先具备下列背景:[a.] UNIX 环境下的简单操作及基本概念.例如: 文件编辑, 文件复制及管道, 输入/输出重定向等概念[b.] C 语言的基本语法及流程控制指令.(awk 指令并不多, 且其中之大部分与C语言中之用法一致, 本手册中对该类指令之语法及特性不再加以繁冗的说明, 读者若欲深究,可自行翻阅相关的C 语言书籍)2.awk概述为什么使用awkawk 是一种程序语言. 它具有一般程序语言常见的功能.因awk语言具有某些特点, 如: 使用直译器(Interpreter)不需先行编译; 变量无类型之分(Typeless), 可使用文字当数组的下标(Associative Array)...等特色. 因此, 使用awk撰写程序比起使用其它语言更简洁便利且节省时间. awk还具有一些内建功能, 使得awk擅于处理具数据行(Record), 字段(Field)型态的资料; 此外, awk内建有pipe的功能, 可将处理中的数据传送给外部的Shell命令加以处理, 再将Shell命令处理后的数据传回awk程序, 这个特点也使得awk程序很容易使用系统资源.由于awk具有上述特色, 在问题处理的过程中, 可轻易使用awk来撰写一些小工具; 这些小工具并非用来解决整个大问题,它们只扮演解决个别问题过程的某些角色, 可藉由Shell所提供的pipe将数据按需要传送给不同的小工具进行处理, 以解决整个大问题. 这种解题方式, 使得这些小工具可因不同需求而被重复组合及重用(reuse); 也可藉此方式来先行测试大程序原型的可行性与正确性, 将来若需要较高的执行速度时再用C语言来改写.这是awk最常被应用之处. 若能常常如此处理问题, 读者可以以更高的角度来思考抽象的问题, 而不会被拘泥于细节的部份.本手册为awk入门的学习指引, 其内容将先强调如何撰写awk程序,未列入进一步解题方式的应用实例, 这部分将留待UNIX进阶手册中再行讨论.如何取得awk一般的UNIX操作系统, 本身即附有awk. 不同的UNIX操作系统所附的awk其版本亦不尽相同. 若读者所使用的系统上未附有awk,可透过anonymous ftp 到下列地方取得:.tw:/pub/gnu.tw:/UNIX/gnu:/pub/gnuawk如何工作为便于解释awk程序架构, 及有关术语(terminology), 先以一个员工薪资档(emp.dat ), 来加以介绍.A125 Jenny 100 210A341 Dan 110 215P158 Max 130 209P148 John 125 220A123 Linda 95 210文件中各字段依次为员工ID, 姓名, 薪资率,及实际工时. ID中的第一码为部门识别码. "A","P"分别表示"组装"及"包装"部门.本小节着重于说明awk程序的主要架构及工作原理, 并对一些重要的名词辅以必要的解释. 由这部分内容, 读者可体会出awk语言的主要精神及awk与其它语程序言的差异处. 为便于说明, 以条列方式说明于后.名词定义●数据行: awk从数据文件上读取数据的基本单位.以上列文件emp.dat为例, awk读入的第一笔数据行是"A125 Jenny 100 210"第二笔数据行是"A341 Dan 110 215"一般而言, 一个数据行就相当于数据文件上的一行资料. (参考: 附录 B 内建变量"RS" )●字段(Field) : 为数据行上被分隔开的子字符串.以数据行"A125 Jenny 100 210"为例,第一栏第二栏第三栏第四栏"A125" "Jenny" 100 210一般是以空格符来分隔相邻的字段. ( 参考: 附录 D 内建变量"FS" )3.如何执行awk于UNIX的命令行上键入诸如下列格式的指令: ( "$"表Shell命令行上的提示符号) $awk 'awk程序' 数据文件文件名则awk会先编译该程序, 然后执行该程序来处理所指定的数据文件.(上列方式系直接把程序写在UNIX的命令行上)awk程序的主要结构:awk程序中主要语法是Pattern { Actions}, 故常见之awk 程序其型态如下:Pattern1 { Actions1 }Pattern2 { Actions2 }......Pattern3 { Actions3 }Pattern 是什么?awk 可接受许多不同型态的Pattern. 一般常使用"关系表达式"(Relational expression) 来当成Pattern.例如:x > 34 是一个Pattern, 判断变量x 与34 是否存在大于的关系.x == y 是一个Pattern, 判断变量x 与变量y 是否存在等于的关系.上式中x >34 , x == y 便是典型的Pattern.awk 提供C 语言中常见的关系运算符(Relational Operators) 如>, <, >=, <=, ==, !=此外, awk 还提供~ (match) 及!~(not match) 二个关系运算符(注一).其用法与涵义如下:若 A 为一字符串, B 为一正则表达式(Regular Expression)A ~B 判断字符串A 中是否包含能匹配(match)B表达式的子字符串.A !~B 判断字符串A 中是否不包含能匹配(match)B表达式的子字符串.例如:"banana" ~ /an/ 整个是一个Pattern.因为"banana"中含有可以匹配/an/ 的子字符串, 故此关系式成立(true),整个Pattern的值也是true.相关细节请参考附录A Patterns, 附录 E Regular Expression(注一:) 有少数awk论著, 把~, !~ 当成另一类的Operator,并不视为一种Relational Operator. 本手册中将这两个运算符当成一种Relational Operator.Actions 是什么?Actions 是由许多awk指令构成. 而awk的指令与C 语言中的指令十分类似.例如:awk的I/O指令: print, printf( ), getline...awk的流程控制指令: if(...){..} else{..}, while(...){...}...(请参考附录B --- "Actions" )awk 如何处理Pattern { Actions } ?awk 会先判断(Evaluate) 该Pattern 的值, 若Pattern 判断后的值为true (或不为0的数字,或不是空的字符串), 则awk将执行该Pattern 所对应的Actions.反之, 若Pattern 之值不为true, 则awk将不执行该Pattern所对应的Actions.例如: 若awk程序中有下列两指令50 > 23 {print "Hello! The word!!" }"banana" ~ /123/ { print "Good morning !" }awk会先判断50 >23 是否成立. 因为该式成立, 所以awk将印出"Hello! The word!!". 而另一Pattern 为"banana" ~/123/, 因为"banana" 内未含有任何子字符串可match /123/, 该Pattern 之值为false, 故awk将不会印出"Good morning !"awk 如何处理{ Actions } 的语法?(缺少Pattern部分)有时语法Pattern { Actions }中, Pattern 部分被省略,只剩{Actions}.这种情形表示"无条件执行这个Actions".awk 的字段变量读入数据行时, awk如何更新(update)这些内建的字段变量?当awk 从数据文件中读取一个数据行时, awk 会使用内建变量$0 予以记录.每当$0 被改动时(例如: 读入新的数据行或自行变更$0,...) awk 会立刻重新分析$0 的字段情况, 并将$0 上各字段的数据用$1, $2, ..予以记录.awk的内建变量(Built-in Variables)awk 提供了许多内建变量, 使用者于程序中可使用这些变量来取得相关信息.常见的内建变量有:例如: awk 从资料文件emp.dat 中读入第一笔数据行"A125 Jenny 100 210" 之后, 程序中:$0 之值将是"A125 Jenny 100 210"$1 之值为"A125"$2 之值为"Jenny"$3 之值为100$4 之值为210$NF 之值为4$NR 之值为1$FILENAME 之值为"emp.dat"awk的工作流程:执行awk时, 它会反复进行下列四步骤.1.自动从指定的数据文件中读取一个数据行.2.自动更新(Update)相关的内建变量之值. 如: NF, NR, $0...3.依次执行程序中所有的Pattern { Actions } 指令.4.当执行完程序中所有Pattern { Actions } 时, 若数据文件中还有未读取的数据, 则反复执行步骤1到步骤4.awk会自动重复进行上述4个步骤, 使用者不须于程序中编写这个循环(Loop).打印文件中指定的字段数据并加以计算awk 处理数据时, 它会自动从数据文件中一次读取一笔记录, 并会将该数据切分成一个个的字段; 程序中可使用$1, $2,... 直接取得各个字段的内容. 这个特色让使用者易于用awk 编写reformatter 来改变量据格式.[ 范例:] 以文件emp.dat 为例, 计算每人应发工资并打印报表.[ 分析:] awk 会自行一次读入一列数据, 故程序中仅需告诉awk 如何处理所读入的数据行.执行如下命令: ( $ 表UNIX命令行上的提示符)$ awk '{ print $2, $3 * $4 }' emp.dat执行结果如下:屏幕出现:Jenny 21000Dan 23650Max 27170John 27500Linda 19950[ 说明:]UNIX命令行上, 执行awk的语法为:$awk 'awk程序' 欲处理的资料文件文件名本范例中的程序部分为{print $2, $3 * $4}.把程序置于命令行时, 程序之前后须以' 括住.emp.dat 为指定给该程序处理的数据文件文件名.本程序中使用: Pattern { Actions } 语法.Pattern 部分被省略, 表无任何限制条件. 故awk读入每笔数据行后都将无条件执行这个Actions.print为awk所提供的输出指令, 会将数据输出到stdout(屏幕).print 的参数间彼此以"," (逗号) 隔开, 印出数据时彼此间会以空白隔开. (参考附录D 内建变量OFS)将上述的程序部分储存于文件pay1.awk 中. 执行命令时再指定awk程序文件之文件名. 这是执行awk的另一种方式, 特别适用于程序较大的情况, 其语法如下:$ awk -f awk程序文件名数据文件文件名故执行下列两命令,将产生同样的结果.$ awk -f pay1.awk emp.dat$ awk '{ print $2, $3 * $4 }' emp.dat读者可使用"-f" 参数,让awk主程序使用“其它仅含awk函数的文件中的函数”其语法如下:$ awk -f awk主程序文件名-f awk函数文件名数据文件文件名(有关awk 中函数的声明与使用于7.4 中说明)awk中也提供与 C 语言中类似用法的printf() 函数. 使用该函数可进一步控制数据的输出格式.编辑另一个awk程序如下, 并取名为pay2.awk{ printf("%6s Work hours: %3d Pay: %5d\n", $2,$3, $3* $4) }执行下列命令$awk -f pay2.awk emp.dat执行结果屏幕出现:Jenny Work hours: 100 Pay: 21000Dan Work hours: 110 Pay: 23650Max Work hours: 130 Pay: 27170John Work hours: 125 Pay: 27500Linda Work hours: 95 Pay: 199504.选择符合指定条件的记录Pattern { Action }为awk中最主要的语法. 若某Pattern之值为真则执行它后方的Action. awk 中常使用"关系表达式" (Relational Expression)来当成Pattern.awk 中除了>, <, ==, != ,...等关系运算符( Relational Operators )外,另外提供~(match),!~(Not Match) 二个关系运算符. 利用这两个运算符, 可判断某字符串是否包含能匹配所指定正则表达式的子字符串. 由于这些特性, 很容易使用awk来编写需要字符串比对, 判断的程序. [ 范例:] 承上例,组装部门员工调薪5%,(组装部门员工之ID以"A"开头)所有员工最后之薪资率若仍低于100, 则以100计.编写awk程序打印新的员工薪资率报表.[分析] : 这个程序须先判断所读入的数据行是否合于指定条件, 再进行某些动作.awk中Pattern { Actions } 的语法已涵盖这种" if ( 条件) { 动作} "的架构. 编写如下之程序, 并取名adjust1.awk$1 ~ /^A.*/ { $3 *= 1.05 } $3<100 { $3 = 100 }{ printf("%s %8s %d\n", $1, $2, $3)}执行下列命令:$awk -f adjust1.awk emp.dat结果如下: 屏幕出现:A125 Jenny 105A341 Dan 115P158 Max 130P148 John 125A123 Linda 100说明:awk的工作程序是: 从数据文件中每次读入一个数据行, 依序执行完程序中所有的Pattern{ Action }指令:$1~/^A.*/ { $3 *= 1.05 }$3 < 100 { $3 = 100 }{printf("%s %8s %d\n",$1,$2,$3)}再从数据文件中读进下一笔记录继续进行处理.第一个Pattern { Action }是: $1 ~ /^A.*/ { $3 *= 1.05 }$1 ~ /^A.*/ 是一个Pattern, 用来判断该笔数据行的第一栏是否包含以"A"开头的子字符串. 其中/^A.*/ 是一个Regular Expression, 用以表示任何以"A"开头的字符串. (有关Regular Expression 之用法参考附录E ).Actions 部分为$3 *= 1.05$3 *= 1.05 与$3 = $3 * 1.05 意义相同. 运算子"*=" 之用法则与 C 语言中一样. 此后与C 语言中用法相同的运算子或语法将不予赘述.第二个Pattern { Actions } 是: $3 <100 {$3 = 100 } 若第三栏的数据内容(表薪资率)小于100, 则调整为100.第三个Pattern { Actions } 是: {printf("%s %8s %d\n",$1, $2, $3 )} 省略了Pattern(无条件执行Actions), 故所有数据行调整后的数据都将被印出.5.awk 中数组awk程序中允许使用字符串当做数组的下标(index). 利用这个特色十分有助于资料统计工作.(使用字符串当下标的数组称为Associative Array)首先建立一个数据文件, 并取名为reg.dat. 此为一学生注册的资料文件; 第一栏为学生姓名, 其后为该生所修课程.Mary O.S. Arch. DiscreteSteve D.S. Algorithm Arch.Wang Discrete Graphics O.S.Lisa Graphics A.I.Lily Discrete Algorithmawk中数组的特性使用字符串当数组的下标(index).使用数组前不须宣告数组名及其大小.例如: 希望用数组来记录reg.dat 中各门课程的修课人数.这情况,有二项信息必须储存:(a) 课程名称, 如: "O.S.","Arch.".. ,共有哪些课程事先并不明确.(b)各课程的修课人数. 如: 有几个人修"O.S."在awk中只要用一个数组就可同时记录上列信息. 其方法如下:使用一个数组Number[ ] :以课程名称当Number[ ] 的下标.以Number[ ] 中不同下标所对映的元素代表修课人数.例如:有2个学生修"O.S.", 则以Number["O.S."] = 2 表之.若修"O.S."的人数增加一人,则Number["O.S."] = Number["O.S."] + 1 或Number["O.S."]++ . 如何取出数组中储存的信息以 C 语言为例, 声明int Arr[100]; 之后, 若想得知Arr[ ]中所储存的数据, 只须用一个循环, 如:for(i=0; i<100; i++) printf("%d\n", Arr[i]);即可. 上式中:数组Arr[ ] 的下标: 0, 1, 2,..., 99数组Arr[ ] 中各下标所对应的值: Arr[0], Arr[1],...Arr[99]但awk 中使用数组并不须事先宣告. 以刚才使用的Number[ ] 而言, 程序执行前, 并不知将来有哪些课程名称可能被当成Number[ ] 的下标.awk 提供了一个指令, 藉由该指令awk会自动找寻数组中使用过的所有下标. 以Number[ ] 为例, awk将会找到"O.S.", "Arch.",...使用该指令时, 须指定所要找寻的数组, 及一个变量. awk会使用该的变量来记录从数组中找到的每一个下标. 例如for(course in Number){....}指定用course 来记录awk 从Number[ ] 中所找到的下标. awk每找到一个下标时, 就用course记录该下标之值且执行{....}中之指令. 藉由这个方式便可取出数组中储存的信息. (详见下例)[ 范例: ] 统计各科修课人数,并印出结果.建立如下程序,并取名为course.awk:{ for( i=2; i <= NF; i++) Number[$i]++ }END{for(course in Number) printf("%10s %d\n", course, Number[course] )}执行下列命令:$awk -f course.awk reg.dat执行结果如下:Graphics 2O.S. 2Discrete 3A.I. 1D.S. 1Arch. 2Algorithm 2[ 说明: ]这程序包含二个Pattern { Actions }指令.{ for( i=2; i <= NF; i++) Number[$i]++ }END{for(course in Number) printf("%10s %d\n", course, Number[course] )}第一个Pattern { Actions }指令中省略了Pattern 部分. 故随着每笔数据行的读入其Actions部分将逐次无条件被执行.以awk读入第一笔资料" Mary O.S. Arch. Discrete" 为例, 因为该笔数据NF = 4(有4个字段), 故该Action 的for Loop中i = 2,3,4.i $i 最初Number[$i] Number[$i]++ 之后i=2时$i="O.S." Number["O.S."]的值从默认的0,变成了1 ;i=3时$i="Arch." Number["Arch."]的值从默认的0,变成了1 ;同理,i=4时$i="Discrete" Number["Discrete"]的值从默认的0,变成了1 ;第二个Pattern { Actions }指令中END 为awk之保留字, 为Pattern 的一种.END 成立(其值为true)的条件是: "awk处理完所有数据, 即将离开程序时. "平常读入数据行时, END并不成立, 故其后的Actions 并不被执行;唯有当awk读完所有数据时, 该Actions才会被执行( 注意, 不管数据行有多少笔, END仅在最后才成立, 故该Actions仅被执行一次.)BEGIN 与END 有点类似, 是awk中另一个保留的Pattern.唯一不同的是: "以BEGIN 为Pattern 的Actions 于程序一开始执行时, 被执行一次."NF 为awk的内建变量, 用以表示awk正处理的数据行中, 所包含的字段个数.awk程序中若含有以$ 开头的自定变量, 都将以如下方式解释:以i= 2 为例, $i = $2 表第二个字段数据. ( 实际上, $ 在awk 中为一运算符(Operator), 用以取得字段数据.)6.awk 程序中使用Shell 命令awk程序中允许呼叫Shell指令. 并提供管道解决awk与系统间数据传递的问题. 所以awk 很容易使用系统资源. 读者可利用这个特点来编写某些适用的系统工具.[ 范例: ] 写一个awk程序来打印出线上人数.将下列程序建文件, 命名为count.awkBEGIN {while ( "who" | getline ) n++print n}并执行下列命令:awk -f count.awk执行结果将会印出目前在线人数[ 说明: ]awk 程序并不一定要处理数据文件. 以本例而言, 仅输入程序文件count.awk, 未输入任何数据文件.BEGIN 和END 同为awk中的一种Pattern. 以BEGIN 为Pattern的Actions ,只有在awk 开始执行程序,尚未开启任何输入文件前, 被执行一次.(注意: 只被执行一次)"|" 为awk 中表示管道的符号. awk 把| 之前的字符串"who"当成Shell上的命令, 并将该命令送往Shell执行, 执行的结果(原先应于屏幕印出者)则藉由pipe送进awk程序中. getline为awk所提供的输入指令.注一: 当Pattern 为BEGIN 或END 时, getline 将由stdin 读取数据, 否则由awk正处理的数据文件上读取数据.getline 一次读取一行数据, 若读取成功则return 1, 若读取失败则return -1, 若遇到文件结束(EOF), 则return 0;本程序使用getline 所return 的数据来做为while 判断循环停止的条件,某些awk版本较旧,并不容许使用者改变$0 之值. 这种版的awk 执行本程序时会产生Error, 读者可于getline 之后置上一个变量(如此, getline 读进来的数据便不会被置于$0 ), 或直接改用gawk便可解决.7.awk 程序的应用实例本节将示范一个统计上班到达时间及迟到次数的程序.这程序每日被执行时将读入二个文件:员工当日到班时间的数据文件( 如下列之arr.dat )存放员工当月迟到累计次数的文件.当程序执行执完毕后将更新第二个文件的数据(迟到次数), 并打印当日的报表.这程序将分成下列数小节逐步完成, 其大纲如下:[7.1] 在到班资料文件arr.dat 之前增加一行抬头"ID Number Arrvial Time", 并产生报表输出到文件today_rpt1 中.< 思考: 在awk中如何将数据输出到文件>[7.2]将today_rpt1 上的数据按员工代号排序, 并加注执行当日日期; 产生文件today_rpt2 <思考awk中如何运用系统资源及awk中Pipe之特性>[7.3] 将awk程序包含在一个shell script文件中[7.4] 于today_rpt2 每日报表上, 迟到者之前加上"*", 并加注当日平均到班时间;产生文件today_rpt3[7.5] 从文件中读取当月迟到次数, 并根据当日出勤状况更新迟到累计数.<思考使用者在awk中如何读取文件数据>某公司其员工到勤时间档如下, 取名为arr.dat. 文件中第一栏为员工代号, 第二栏为到达时间. 本范例中, 将使用该文件为数据文件.1034 7:261025 7:271101 7:321006 7:451012 7:461028 7:491051 7:511029 7:571042 7:591008 8:011052 8:051005 8:12重定向输出到文件awk中并未提供如C 语言中之fopen() 指令, 也未有fprintf() 文件输出这样的指令. 但awk 中任何输出函数之后皆可借助使用与UNIX 中类似的I/O 重定向符, 将输出的数据重定向到指定的文件; 其符号仍为> (输出到一个新产生的文件) 或>> ( 添加输出的数据到文件末尾).[例:]在到班数据文件arr.dat 之前增加一行抬头如下:"ID Number Arrival Time", 并产生报表输出到文件today_rpt1中建立如下文件并取名为reformat1.awkBEGIN { print " ID Number Arrival Time" > "today_rpt1"print "===========================" > "today_rpt1"}{ printf(" %s %s\n", $1,$2 ) > "today_rpt1" }执行:$awk -f reformat1.awk arr.dat执行后将产生文件today_rpt1, 其内容如下:ID Number Arrival Time============================1034 7:261025 7:271101 7:321006 7:451012 7:461028 7:491051 7:511029 7:571042 7:591008 8:011052 8:051005 8:12[ 说明: ]awk程序中, 文件名称today_rpt1 的前后须以" (双引号)括住, 表示today_rpt1 为一字符串常量. 若未以"括住, 则today_rpt1 将被awk解释为一个变量名称.在awk中任何变量使用之前, 并不须事先声明. 其初始值为空字符串(Null string) 或0.因此程序中若未以" 将today_rpt1 括住, 则today_rpt1 将是一变量, 其值将是空字符串, 这会在执行时造成错误(Unix 无法帮您开启一个以空字符串为文件名的文件).因此在编辑awk程序时, 须格外留心. 因为若敲错变量名称,awk在编译程序时会认为是一新的变量, 并不会察觉. 因此往往会造成运行时错误.BEGIN 为awk的保留字, 是Pattern 的一种.以BEGIN 为Pattern 的Actions 于awk程序刚被执行尚未读取数据文件时被执行一次, 此后便不再被执行.读者或许觉得本程序中的I/O重定向符号应使用" >>" (append)而非" >".本程序中若使用">" 将数据重导到today_rpt1, awk 第一次执行该指令时会产生一个新档today_rpt1, 其后再执行该指令时则把数据追加到today_rpt1文件末, 并非每执行一次就重开一个新文件.若采用">>"其差异仅在第一次执行该指令时, 若已存在today_rpt1则awk 将直接把数据append在原文件之末尾. 这一点, 与UNIX中的用法不同.awk 中如何利用系统资源awk程序中很容易使用系统资源. 这包括在程序中途调用Shell 命令来处理程序中的部分数据; 或在调用Shell 命令后将其产生的结果交回awk 程序(不需将结果暂存于某个文件). 这一过程是借助awk 所提供的管道(虽然有些类似Unix 中的管道, 但特性有些不同),及一个从awk 中呼叫Unix 的Shell 命令的语法来达成的.[例:] 承上题, 将数据按员工ID排序后再输出到文件today_rpt2 , 并于表头附加执行时的日期.[ 分析: ]awk 提供与UNIX 用法近似的pipe, 其记号亦为"|". 其用法及含意如下:awk程序中可接受下列两种语法:[a. 语法] awk output 指令| "Shell 接受的命令"( 如: print $1,$2 | "sort -k 1" )[b. 语法] "Shell 接受的命令" | awk input 指令( 如: "ls " | getline)注: awk input 指令只有getline 一个.awk output 指令有print, printf() 二个.在a 语法中, awk所输出的数据将转送往Shell , 由Shell 的命令进行处理.以上例而言, print 所输出的数据将经由Shell 命令"sort -k 1"排序后再送往屏幕(stdout).上列awk程序中, "print$1, $2" 可能反复执行很多次, 其输出的结果将先暂存于pipe 中,等到该程序结束时, 才会一并进行"sort -k 1".须注意二点: 不论print $1, $2 被执行几次, "sort -k 1" 的执行时间是"awk程序结束时", "sort -k 1" 的执行次数是"一次".在 b 语法中, awk将先调用Shell 命令. 其执行结果将通过pipe 送入awk程序,以上例而言, awk先让Shell 执行"ls",Shell 执行后将结果存于pipe, awk指令getline再从pipe 中读取数据.使用本语法时应留心: 以上例而言,awk "立刻"调用Shell 来执行"ls", 执行次数是一次. getline 则可能执行多次(若pipe中存在多行数据).除上列a, b 二中语法外, awk程序中其它地方如出现像"date", "cls", "ls"... 这样的字符串, awk只把它当成一般字符串处理.建立如下文件并取名为reformat2.awk# 程序reformat2.awk# 这程序用以练习awk中的pipeBEGIN {"date" | getline # Shell 执行"date". getline 取得结果并以$0记录print " Today is " , $2, $3 >"today_rpt2"print "=========================" > "today_rpt2"print " ID Number Arrival Time" >"today_rpt2"close( "today_rpt2" )}{printf( "%s %s\n", $1 ,$2 ) | "sort -k 1 >>today_rpt2"}执行如下命令:awk -f reformat2.awk arr.dat执行后, 系统会自动将sort 后的数据追加( Append; 因为使用" >>") 到文件today_rpt2末端. today_rpt2 内容如下:Today is 09月21日=========================ID Number Arrival Time1005 8:121006 7:451008 8:011012 7:461025 7:271028 7:491029 7:571034 7:261042 7:591051 7:511052 8:051101 7:32[ 说明: ]awk程序由三个主要部分构成:[ i.] Pattern { Action} 指令[ ii.] 函数主体. 例如: function double( x ){ return 2*x } (参考第11节Recursive Program ) [ iii.] Comment ( 以# 开头识别之)awk 的输入指令getline, 每次读取一列数据. 若getline之后未接任何变量, 则所读入之资料将以$0 记录, 否则以所指定的变量储存之.[ 以本例而言] :执行"date" | getline 后, $0 之值为"2007年09月21日星期五14:28:02 CST",当$0 之值被更新时, awk将自动更新相关的内建变量, 如: $1,$2,..,NF.故$2 之值将为"09月", $3之值将为"21日".(有少数旧版的awk不允许即使用者自行更新(update)$0的值,或者更新$0时,它不会自动更新$1,$2,..NF. 这情况下, 可改用gawk或nawk. 否则使用者也可自行以awk字符串函数split()来分隔$0上的数据)本程序中printf() 指令会被执行12次( 因为有arr.dat中有12行数据), 但读者不用担心数据被重复sort了12次. 当awk结束该程序时才会close 这个pipe , 此时才将这12行数据一次送往系统,并呼叫"sort -k 1 >> today_rpt2" 处理之.awk提供另一个调用Shell命令的方法, 即使用awk函数system("shell命令")例如:$ awk 'BEGIN{system("date > date.dat")getline < "date.dat"print "Today is ", $2, $3}'但使用system( "shell 命令" ) 时, awk无法直接将执行中的部分数据输出给Shell 命令. 且Shell 命令执行的结果也无法直接输入到awk中.执行awk 程序的几种方式本小节中描述如何将awk程序直接写在shell script 之中. 此后使用者执行awk 程序时, 就不需要每次都键入" awk -f program datafile" .script 中还可包含其它Shell 命令, 如此更可增加执行过程的自动化.建立一个简单的awk程序mydump.awk, 如下:{print}这个程序执行时会把数据文件的内容print 到屏幕上( 与cat功用类似).print 之后未接任何参数时, 表示"print $0".若欲执行该awk程序, 来印出文件today_rpt1 及today_rpt2 的内容时,必须于UNIX 的命令行上执行下列命令:方式一awk -f mydump.awk today_rpt1 today_rpt2方式二awk '{print}' today_rpt1 today_rpt2第二种方式系将awk 程序直接写在Shell 的命令行上, 这种方式仅适合较短的awk程序.方式三建立如下之shell script, 并取名为mydisplay,#!/bin/sh# 注意以下的awk 与' 之间须有空白隔开awk '{print}' $*# 注意以上的' 与$* 之间须有空白隔开。