I have the following script in awk that sums all columns in a file that I pipe to it:#sum_all.awk{   for (i=1; i<=NF; i++) { sum[i]+= $i }   }END { for (i=1; i<=NF; i++ ) { printf %d , sum[i] } }e.g.: cat my_file.txt | awk -f sum_all.awk with my_file.txt:5 7 81 0 2outputs:6 7 10 %How can I get rid of that last character %?
Extra % in output of awk script
shell script;awk
As manatwork already commented, the % is not part of the output from awk, it's the next prompt from the shell. In the END block, for this input file, there are three calls to printf. The first outputs 6 and a space, the second outputs 7 and a space, and the third outputs 10 and a space. After this, awk exits, and the shell prints its prompt.If a command prints some output that does not end in a newline (or, more generally, if it doesn't leave the cursor at the beginning of a line), thendepending on your shell's configuration, the shell will either print its prompt after the command's output on the same line, or the shell might erase the unterminated line and print its prompt at the beginning of the line.To make sure a command's output is fully visible, make sure that it ends in a newline (unless the command produces no output, of course). In unix systems, a non-empty text file always ends with a newline, because a text files consists of a (possibly empty) series of lines, each of which consists of a (possibly empty) series of characters other than newline (and null bytes). Most utilities tend to be designed to deal primarily with text files, so make sure that your command's output is a valid text file.After printing the fields, print a \n (the awk notation for a newline character), or call the print function, which adds a newline after the printed text.END { for (i=1; i<=NF; i++) printf %d , sum[i]; print ; }or, to avoid having an extra space at the end of the line:END { for (i=1; i<NF; i++) printf %d , sum[i]; printf %d\n, sum[NF]; }orEND { printf %d; for (i=2; i<=NF; i++) printf  %d, sum[i]; print ; }orEND { for (i=1; i<NF; i++ ) printf %d%s, sum[i], (i==NR ? \n :  ); }