当前位置:网站首页>Awk command exercise
Awk command exercise
2022-07-06 17:45:00 【JohnnyFang】
As one of the three swordsmen of the text ,awk The command has powerful functions in filtering data . Use awk On command , Fields separated by separators ( Column column, Domain field) Mark $1,$2...$n It's called a domain identifier ,$0 For all domains ( and shell Medium variable $ They have different meanings ), Each line becomes record, If omitted action, By default print $0 The operation of .
The requirements of this exercise are : Use awk Get... Separated by colons /ettc/passwd File first column .
perform cat /etc/passwd command , You can view all the information in the specified file , We need to screen out root、bin、daemon The information in this column ( Here's the picture ).
awk Common options include :
①-F “ Separator ” Indicates the field separator used for input , The default delimiter is several consecutive white space characters ;
②-v var=value Variable assignment
Just these two options can be used in this exercise , First look -F Options . Because it is separated by colon ,-F Followed by :( Add it here or not “” Fine ); The first column is filtered , The domain ID at the time of output is $1, The perform awk -F: '{print $1}' /etc/passwd Command to get the first column ( Here's the picture ).
Look again. -v Options , Use -v Option , We can use awk Built in variables in FS( Enter field separator , The default is blank , Function equivalent to -F), That is, the variable is assigned FS=":", perform awk -v FS=":" '{print $1}' /etc/passwd Can get /ettc/passwd File first column ( Here's the picture ).
边栏推荐
猜你喜欢
[ASM] introduction and use of bytecode operation classwriter class
05 personal R & D products and promotion - data synchronization tool
Application service configurator (regular, database backup, file backup, remote backup)
Vscode matches and replaces the brackets
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
How to use scroll bars to dynamically adjust parameters in opencv
PySpark算子处理空间数据全解析(4): 先说说空间运算
Concept and basic knowledge of network layering
Establishment of graphical monitoring grafana
Wordcloud colormap color set and custom colors
随机推荐
04 products and promotion developed by individuals - data push tool
Single responsibility principle
EasyRE WriteUp
遠程代碼執行滲透測試——B模塊測試
Virtual machine startup prompt probing EDD (edd=off to disable) error
Flexible report v1.0 (simple version)
MySQL Advanced (index, view, stored procedures, functions, Change password)
虚拟机启动提示Probing EDD (edd=off to disable)错误
The art of Engineering
06 products and promotion developed by individuals - code statistical tools
Huawei certified cloud computing hica
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
Automatic operation and maintenance sharp weapon ansible Foundation
学 SQL 必须了解的 10 个高级概念
Example of batch update statement combining update and inner join in SQL Server
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
Wechat applet obtains mobile number
connection reset by peer
Unity小技巧 - 绘制瞄准准心
EasyCVR授权到期页面无法登录,该如何解决?