当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Web API系列(三)统一异常处理
- Didi's distributed ID generator (tinyid), easy to use
- Chinese sub forum of | 2020 PostgreSQL Asia Conference: Pan Juan
- 【笔记】Error while loading PyV8 binary: exit code 1解决方法
- Mac新手必备小技巧
- Logo design company, Nanjing
- Design pattern of facade and mediator
- Application and principle of handlermethodargumentresolver
- In simple terms, the large front-end framework angular6 practical course (angular6 node.js 、keystonejs、
- 想要忘记以前连接到Mac的WiFi网络,试试这个方法!
猜你喜欢

失眠一个整晚上

Jenkins pipline stage setting timeout

Using JSON webtoken (JWT) to generate token in nodejs

如何使用甘特图图层和筛选器

Shanghai Pudong Development Bank, which frequently receives penalty tickets, has been cheated by hundreds of millions of yuan in loans, and lacks of internal control?

Benefits and functions of auto maintenance app development

带你深入了解 GitLab CI/CD 原理及流程

vue踩坑:axios使用this指针

Dynamsoft barcode reader v7.5!

python3操作gitlab
随机推荐
idea 激活到 2089 失效
pc端与移动端适配解决方案之rem
CI / CD of gitlab continuous integrated development environment
yum [Errno 256] No more mirrors to try 解决方法
Jenkins pipline stage setting timeout
Exclusive interview with alicloud database of | 2020 PostgreSQL Asia Conference: Wang Xu
使用“1”个参数调用“DownloadString”时发生异常:“操作超时”
垃圾分类知识竞赛
10000! Ideal car recalls all defective cars: 97 accidents have occurred and losses will be expanded
PHP backdoor hiding skills
Web API interface design: swaggerui document / unified response format / unified exception handling / unified authority verification
频收罚单的浦发银行:增收不增利,曾遭骗贷数亿元,内控缺位?
The JS solution cannot be executed after Ajax loads HTML
What should be considered in the promotion plan outside the station?
8.Swarm创建维护和水平扩展Service
条形码识别性能低,如何优化Dynamsoft Barcode Reader解码性能
失眠一个整晚上
Jenkins入门(二)声明式流水线Jenkins Pipeline
Web API系列(三)统一异常处理
Idea activation to 2089 failure