当前位置:网站首页>[one day learning awk] Fundamentals
[one day learning awk] Fundamentals
2022-06-30 12:46:00 【Programmer Xiao Li】
1. awk What is it ?
awk yes linux Environment , A syntax sugar similar to regular expressions in code .
2. awk Statement composition of
awk The sentence of is mainly divided into three parts :
One is BEGIN, This part mainly completes initialization , Only once , not essential .
Then there is the repeated part ,repeat. This section performs a corresponding operation for each match .
And finally END part , Generally, the closing operation is completed , Only once , not essential .
3. Try to use BEGIN
First , We create a text ,vi marks.txt
1) Learnfk Physics 80
2) Toolfk Maths 90
3) Chromefk Biology 87
4) Poemfk English 85
5) Nesfk History 89
Let's take a look at the content first :
We try to use awk sentence , stay marks.txt Add a sentence before the text "This is the title."
awk 'BEGIN{printf "This is the title.\n"} {print}' marks.txt
This sentence is actually printed in front of the text , explain BEGIN Is the first execution , And only once
4. No, BEGIN The sentence of
We can execute repeated statements directly
awk '{print}' marks.txt
5. Write command to script
vi command.awk
And then use awk -f command.awk marks.txt perform
The effect is the same as direct execution .
6. Command specifies the variable
Use -v Variable can be specified , for example
awk -v name=Bob 'BEGIN{printf "hello, %s\n", name}{print}' marks.txt
We can use it directly awk The specified variable .
边栏推荐
- 如何利用AI技术优化独立站客服系统?听听专家怎么说!
- Grep match lookup
- Substrate 源码追新导读: Pallet Alliance 并入主线,
- Visual Studio配置Qt并通过NSIS实现项目打包
- Inner join and outer join of MySQL tables
- Q-learning notes
- 数据仓库建设之确定主题域
- Tencent two sides: @bean and @component are used on the same class. What happens?
- Redis-緩存問題
- Idea has a new artifact, a set of code to adapt to multiple terminals!
猜你喜欢
随机推荐
【一天学awk】数组的使用
[target tracking] |pytracking configuring win to compile prroi_ pool. pyd
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年6月29日21:59:34
如何利用AI技术优化独立站客服系统?听听专家怎么说!
Introduction to new features of ES6
Charles打断点修改请求数据&响应数据
Getting started with the go language is simple: go handles XML files
[QNX Hypervisor 2.2用户手册]6.2.3 Guest与外部之间通信
Clipboardjs - development learning summary 1
How to use AI technology to optimize the independent station customer service system? Listen to the experts!
Substrate 源码追新导读: 波卡系波卡权重计算全面更新, Governance 2.0 版本的优化和调整
FFMpeg AVBufferPool 的理解与掌握
Sarsa notes
Hisilicon 3559 sample parsing: Venc
【MySQL】MySQL的安装与配置
Google refutes rumors and gives up tensorflow. It's still alive!
Android development interview real question advanced version (with answer analysis)
Apple executives openly "open the connection": Samsung copied the iPhone and only added a large screen
视频按每100帧存一个文件夹,处理完再图片转视频
Sqlserver query code is 936 simplified Chinese GBK. Should I write 936 or GBK?