I want the variable sum/NR to be printed side-by-side in each iteration. How do we avoid awk from printing newline in each iteration ? In my code a newline is printed by def
If Perl is an option, here is a solution using fedorqui's example:
seq 5 | perl -ne 'chomp; print "$_ "; END{print "\n"}'
Explanation: chomp removes the newline print "$_ " prints each line, appending a space the END{} block is used to print a newline
chomp
print "$_ "
END{}
output: 1 2 3 4 5
1 2 3 4 5