不要读取awk命令文件中文件的第一行 [英] do not read first line of file in awk command file

查看:92
本文介绍了不要读取awk命令文件中文件的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了麻烦,因此我的awk命令列表不会读取数据文件的第一行.它必须读取除第一行以外的每一行,然后将运动员和年份连接成一个字符串.在程序的后面,我使用一个数组,但没有列出所有代码.数据文件的前两行如下所示.我需要这样做,因此它不会读取标题行,而只会从第一位运动员开始.任何帮助都会很棒!

I am having trouble making it so that my list of awk commands does not read the first line of a data file. It must read each line except for the first, and then concatenate the athlete and year into a string. Later in the program I use an array, I did not list all of the code. The first two lines of the data file are listed below. I need to make it so it does not read the heading line and only starts with the first athlete. Any help on this would be great!

脚本:

BEGIN{
FS=","
cnt=0; sum=0;
}
{
name=$1
year=$4
ayStr = name "," " " year

推荐答案

在处理文件行的块之前使用NR > 1:

Use NR > 1 before the block that processes the file lines:

BEGIN {
FS=","
cnt=0; sum=0;
}
NR > 1 {
name=$1
year=$4
ayStr = name "," " " year

NR是文件中的行号,因此它仅处理1之后的行.

NR is the line number in the file, so it only processes lines after 1

这篇关于不要读取awk命令文件中文件的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆