To force awk
not to print a newline at the end of the output, you can use the ORS
(Output Record Separator) variable. By default, awk
adds a newline character to the end of each output record. You can use the ORS
variable to change this separator to something else, or to suppress it entirely.
For example, to suppress the newline character at the end of the output, you can use the following awk
command:
awk 'BEGIN {ORS=""; print "Hello, World!"}'Source:www.lautturi.com
This will print the string "Hello, World!"
without a newline character at the end.
Alternatively, you can use the printf
function to control the output format more precisely. The printf
function allows you to specify a format string that determines how the output will be printed, including the newline character at the end. For example, to print the string "Hello, World!"
without a newline character at the end, you could use the following awk
command:
awk 'BEGIN {printf "Hello, World!"}'