[英]AWK keep header of input file in output
i have an input file that looks like this: 我有一个看起来像这样的输入文件:
datetime,num1,num2
10-01-2015 00:00,1,2
10-01-2015 00:00,4,5
my awk code looks like this: 我的awk代码如下所示:
awk -F"," '{thisid=substr($1,1,10);if(lastid!=thisid)
{print lastid"|"cnt1"|"cnt2;cnt1=0;cnt2=0;lastid=thisid;}
if($2>=40){cnt1+=1;}if($3>=40){cnt2+=1;}
lastid=thisid;}' input > output
i want my output to have the header still: 我希望我的输出仍然具有标题:
datetime,num1,num2
10-01-2015,0,0
10-01-2015,0,0
currently output of header just look like this: 当前标头的输出如下所示:
datetime|1|1
i dont want to manually print the header. 我不想手动打印标题。
在左括号({)之前,添加:
NR == 1 {print; next}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.