当前位置:网站首页>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
边栏推荐
- SQL: query duplicate data and delete duplicate data
- Leetcode 994, rotten orange
- go slice
- Come in and teach you how to solve the problem of port occupation
- Matlab matrix index problem
- MySQL 存储过程和函数
- Bracket matching -- [implementation of one-dimensional array]
- LeetCode 994、腐烂的橘子
- 100天拿下11K,转岗测试的超全学习指南
- Go zero framework database avoidance Guide
猜你喜欢
go slice
MySQL进阶之表的增删改查
內網滲透之DOS命令
Commande dos pour la pénétration de l'Intranet
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
JS arrow function user and processing method of converting arrow function into ordinary function
Linux中,MySQL的常用命令
一些接地气的话儿
DOS command of Intranet penetration
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
随机推荐
MySQL stored procedures and functions
三十一. `prototype`显示原型属性和`__proto__`隐式原型属性
Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high
MySQL数据库常识之储存引擎
Imitation Baidu map realizes the three buttons to switch the map mode by automatically shrinking the bottom
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
Identifier CV is not defined in opencv4_ CAP_ PROP_ FPS; CV_ CAP_ PROP_ FRAME_ COUNT; CV_ CAP_ PROP_ POS_ Frames problem
Psychological formula for converting RGB to gray value
How to configure SSH public key in code cloud
Shanghai a répondu que « le site officiel de la farine est illégal »: l'exploitation et l'entretien négligents ont été « noirs » et la police a déposé une plainte
Leetcode 1337. Row K with the weakest combat effectiveness in the matrix
Resolve the error - error identifier 'attr_ id‘ is not in camel case camelcase
Thirty What are VM and VC?
Async function ------ ES6
【PTA】L1-006 连续因子
LeetCode 116. Populate the next right node pointer for each node
Install MySQL 5.0 under Linux 64bit 6 - the root password cannot be modified
6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam
100天拿下11K,转岗测试的超全学习指南
XXXI` Prototype ` displays prototype properties and`__ proto__` Implicit prototype properties