当前位置:网站首页>Awk implements SQL like join operation
Awk implements SQL like join operation
2020-11-07 18:55:00 【Irving the procedural ape】
awk、grep and sed go by the name of linux Three swordsmen , in fact grep and awk I also use it in my daily work (sed Use less ), Maybe some people are right about awk Less understanding , Let me give you a general introduction to . Many people think awk It's just a text processing tool , In fact, they use it the same way . But it's actually a language , Have mathematical operators 、 Process control statements , It even encapsulates many built-in variables and functions for text processing , This makes it powerful in text processing . If grep Can only do data filtering , that awk It can also process data 、 Analyze and even generate reports , After all, it's a complete programming language .
Because this article is not awk Getting started with , If you want to get started, I recommend Ruan Yifeng awk Introductory tutorial and Left ear mouse AWK A concise tutorial .
Back to my topic today , Today I'd like to show you something I use a lot awk Scene . Because we do back-end development , Often when doing data analysis, there will be such a problem ,1. Facing hundreds of thousands of data , We need to screen out hundreds and thousands of specific key The data of .2. For these millions of data , Directed against id Fields complement other fields .
There may be mastery of excel My classmates jumped out and said “ Is this ,so easy,vlookup That's it !” , in fact ,excel It does solve the problem , But it's a little heavy , Even sometimes we can't use it on the server excel. What other ways ? For the two scenes I'm talking about , Actually, think about it , Is it right? sql Two watches in Chinese join Can solve the problem . In fact, you don't really need to put files in the database , Only need to use awk One order can solve .
example
Let's take the question like , Suppose there are two files ,score.txt Save the student number + Performance data , Another one name.txt Save the student number + Name data , Now you want to know how many points everyone has baked .
score.txt
id score 1 872 673 684 755 906 1007 0
name.txt
id name 1 Zhang San 2 Li Si 3 Wang Wu 4 Zhao er 5 Lennon 6 Big bear
You want a copy with a student number Name and grade data , It looks like this .
id score name 1 87 Zhang San 2 67 Li Si 3 68 Wang Wu 4 75 Zhao er 5 90 Lennon 6 100 Big bear 7 0
use awk How easy it is to generate such data ? Just one line of code , You can save name.txt and score.txt, And then execute the following command to try .
awk 'ARGV[1]==FILENAME {map[$1]=$2} ARGV[2]==FILENAME {print $0, map[$1]}' name.........
版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢
边栏推荐
- Image processing toolkit imagexpresshow to view events
- HandlerMethodArgumentResolver使用和原理
- STlink下载出现st-link usb communication error解决方法
- Mate 40系列发布 搭载华为运动健康服务带来健康数字生活
- Plug in bilibilibili new version 0.5.5
- 【笔记】Error while loading PyV8 binary: exit code 1解决方法
- How to use Gantt chart layers and filters
- Win7 how to quickly type CMD and get to the required directory
- confd
- 谈了多年的数字化转型,为什么还有很多企业依然“口头管理”
猜你喜欢
![[note] error while loading pyv8 binary: exit code 1 solution](/img/3b/00bc81122d330c9d59909994e61027.jpg)
[note] error while loading pyv8 binary: exit code 1 solution

嘉宾介绍|2020 PostgreSQL亚洲大会中文分论坛:潘娟

How to use Gantt chart layers and filters

MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法
![yum [Errno 256] No more mirrors to try 解决方法](/img/3b/00bc81122d330c9d59909994e61027.jpg)
yum [Errno 256] No more mirrors to try 解决方法

Python3 operating gitlab

Experiment one

Classroom exercises

Benefits and functions of auto maintenance app development

How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
随机推荐
Come on in! Take a few minutes to see how reentrantreadwritelock works!
New features of vue3
idea 激活到 2089 失效
If you want to forget the WiFi network you used to connect to your Mac, try this!
How to optimize the decoding performance of dynamsoft barcode reader
[original] the impact of arm platform memory and cache on the real-time performance of xenomai
Mate 40 series launch with Huawei sports health service to bring healthy digital life
10000! Ideal car recalls all defective cars: 97 accidents have occurred and losses will be expanded
甘特图对活动进行分组教程
Git SSH bad permissions
FreeSWITCH视频会议“标准”解决方案
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
9. Routingmesh service communication between clusters
Andque.
JS string - string string object method
快進來!花幾分鐘看一下 ReentrantReadWriteLock 的原理!
HandlerMethodArgumentResolver使用和原理
[note] error while loading pyv8 binary: exit code 1 solution
课堂练习
pc端与移动端适配解决方案之rem