当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 11. Service update
- Git SSH bad permissions
- Nanjing logo design and production, guide VI system design
- Tips for Mac novices
- Design pattern of facade and mediator
- idea 激活到 2089 失效
- REM: the solution of PC and mobile
- Application and principle of handlermethodargumentresolver
- And how to solve the conflict between pop-up menu and pop-up menu
- C語言重點——指標篇(一文讓你完全搞懂指標)| 從記憶體理解指標 | 指標完全解析
猜你喜欢
OpenCV計算機視覺學習(10)——影象變換(傅立葉變換,高通濾波,低通濾波)
Benefits and functions of auto maintenance app development
聊聊先享後付
一种超参数优化技术-Hyperopt
课堂练习
垃圾分类知识竞赛
JS array the usage of array is all here (array method reconstruction, array traversal, array de duplication, array judgment and conversion)
图像处理工具包ImagXpress使用教程,如何查看事件
Nanjing logo design and production, guide VI system design
confd
随机推荐
Git submission specification
Blazor 準備好為企業服務了嗎?
If you want to forget the WiFi network you used to connect to your Mac, try this!
Idea activation to 2089 failure
Design pattern of facade and mediator
Win10官方1909版本无法打开windows安全中心中病毒和威胁防护的实时保护解决方案。
A kind of super parameter optimization technology hyperopt
11.Service更新
VARCHART XGantt入门教程
Python 3 operates the Jenkins module API
谈了多年的数字化转型,为什么还有很多企业依然“口头管理”
Solution to st link USB communication error in stlink Download
站外推广的计划需要考虑哪些呢?
Yum [errno 256] no more mirrors to try solution
Mate 40系列发布 搭载华为运动健康服务带来健康数字生活
Nanjing logo design and production, guide VI system design
LEADTOOLS如何检测,读取和写入条形码
如何利用PopupWindow实现弹出菜单并解决焦点获取以及与软键盘冲突问题
Application and principle of handlermethodargumentresolver
chrome浏览器跨域Cookie的SameSite问题导致访问iframe内嵌页面异常