0

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 -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.

1
  • Do you find it improves readability to not use any white space in your scripts? Commented Oct 9, 2015 at 5:34

1 Answer 1

4

Before the opening brace ({), add:

NR == 1 {print; next}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.