当前位置:网站首页>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 ).
边栏推荐
- 2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
- 04个人研发的产品及推广-数据推送工具
- [getting started with MySQL] fourth, explore operators in MySQL with Kiko
- Flink parsing (V): state and state backend
- 一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升
- Integrated development management platform
- Flink analysis (II): analysis of backpressure mechanism
- [translation] principle analysis of X Window Manager (I)
- Total / statistics function of MySQL
- 06 products and promotion developed by individuals - code statistical tools
猜你喜欢
Grafana 9 正式发布,更易用,更酷炫了!
Unity particle special effects series - treasure chest of shining stars
Zen integration nails, bugs, needs, etc. are reminded by nails
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
PyTorch 提取中间层特征?
Optimization of middle alignment of loading style of device player in easycvr electronic map
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
Spark accumulator and broadcast variables and beginners of sparksql
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
Basic configuration and use of spark
随机推荐
面试突击63:MySQL 中如何去重?
Example of batch update statement combining update and inner join in SQL Server
【MySQL入门】第一话 · 初入“数据库”大陆
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
Quick start of Hongmeng system
The art of Engineering (3): do not rely on each other between functions of code robustness
Error: Publish of Process project to Orchestrator failed. The operation has timed out.
2022年大厂Android面试题汇总(一)(含答案)
Flink parsing (IV): recovery mechanism
Kali2021 installation and basic configuration
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
[introduction to MySQL] the first sentence · first time in the "database" Mainland
Integrated development management platform
Establishment of graphical monitoring grafana
灵活报表v1.0(简单版)
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
Debug and run the first xv6 program
基于STM32+华为云IOT设计的智能路灯
MySQL advanced (index, view, stored procedure, function, password modification)