awk without printing newline

前端 未结 6 1380
失恋的感觉
失恋的感觉 2020-12-12 14:24

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

6条回答
  •  执笔经年
    2020-12-12 14:56

    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

    output: 1 2 3 4 5

提交回复
热议问题