I was planning on solving the first question of aoc2022, using awk, inspired by someone's idea from GitHub. I need to find the sum of elements between the blank spaces.
Here's the awk program,
#!/usr/bin/awk -f
BEGIN {
current_count = 0 ;
}
NF == 0 {
print current_count ;
current_count = 0 ;
next ;
}
{ current_count += $0 }
But when I run this, I'm not getting any outputs.
awk -f calorie-count.awk < input.txt
Any help is appreciated.
The input almost looks like this, with white spaces in between.
7569
1357
10134
4696
4423
8869
3562
6597
4038
9038
1352
8005
4811
6281
3961
4023
7234
3510
7728
1569
4583
7495
3941
6015
6531
2637
18211
19347
16113
7314
3359
7199
4527
5384
1752
2422
6301
1923
5957
3000
6835
1986
END { print current_count }
instead.dos2unix input.txt
on then try again.END { print current_count }
after your first fix (changing CRLF to LF whichdos2unix
commnad does)