Difference between revision 2 and current revision

Summary: Rollback to 2011-07-05 09:31 UTC

No diff available.

"print" prints a newline by default. If you don't want a newline, you can use printf instead it is straightforward, just remember to use a format string and avoid putting data in it.

  printf "%s",$0 #prints the record without adding a newline

If you want to join the lines with another characters you can do something like:

   awk '{printf "%s%s",separator,$0;separator="|"}END{printf "\n"}'

"print" does print a newline by default, but that's not the whole truth, in fact print adds the character in ORS, so you can also change ORS to "remove" the newlines

  printf "%s\n" foo bar | awk -v ORS="|" '{print $0}'

The "drawback" of this method is that a trailing ORS is always added.