当前位置:网站首页>Awk example skills
Awk example skills
2022-04-23 20:43:00 【baboon_ chen】
One 、 Transpose files
hypothesis file.txt The contents of the document are as follows :
name age
alice 21
ryan 30
It should output :
name alice ryan
age 21 30
convert.awk
##
## awk -f convert.awk file.txt
{
# The code in this brace is Processing of text
# NF A number of columns ,NR Indicates the number of lines read
# Be careful for Medium i from 1 Start ,i There is no type before
for (i=1; i<=NF; i++){
# For each column
if(NR==1){
# If it's the first line
# Will be the first i The value of the column is stored in res[i],$i It means the first one i The value of the column ,i Is the subscript of the array , Take the column serial number as the subscript ,
# Arrays can be used directly without definition
res[i]=$i;
}
else{
# Not the first line , Map this line to i The values of the columns are spliced into res[i]
res[i]=res[i] " " $i
}
}
}
# BEGIN{} What to do before scanning a file ;END{} What to do after file scanning .
END{
# The output array
for (i=1; i<=NF; i++){
print res[i]
}
}
版权声明
本文为[baboon_ chen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210546351155.html
边栏推荐
- The ODB model calculates the data and outputs it to excel
- 居家第二十三天的午饭
- Three. Based on ply format point cloud voxel model JS upload interface writing
- Syntaxerror: unexpected token r in JSON at position 0
- MySQL基础合集
- Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
- pikachuxss如何获取cookie靶场,返回首页总是失败
- Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
- Some basic knowledge of devexpress report development
- LeetCode 709、转换成小写字母
猜你喜欢

Matlab analytic hierarchy process to quickly calculate the weight

100天拿下11K,转岗测试的超全学习指南

41. 缺失的第一个正数

Identifier CV is not defined in opencv4_ CAP_ PROP_ FPS; CV_ CAP_ PROP_ FRAME_ COUNT; CV_ CAP_ PROP_ POS_ Frames problem

Customize timeline component styles

The ODB model calculates the data and outputs it to excel

內網滲透之DOS命令

Elastic box model

Some basic knowledge of devexpress report development

On BIM data redundancy theory
随机推荐
SQL gets the latest record of the data table
go map
MySQL stored procedures and functions
一. js的深拷贝和浅拷贝
MySQL 存储过程和函数
Summary and effect analysis of methods for calculating binocular parallax
2021-06-29 C escape character cancellation and use
Flex layout
【PTA】L1-002 打印沙漏
GO语言开发天天生鲜项目第三天 案例-新闻发布系统二
Awk print special characters
A login and exit component based on token
中创存储|想要一个好用的分布式存储云盘,到底该怎么选
GSI-ECM工程建设管理数字化平台
LeetCode 542、01 矩阵
Cmake project under vs2019: calculating binocular parallax using elas method
Scripy tutorial - (2) write a simple crawler
居家第二十三天的午饭
Solve the Chinese garbled code of URL in JS - decoding
Scrapy教程 - (2)寫一個簡單爬蟲