How to print all columns using AWK

In AWK, is there a way to print all columns? I do not want to print them like this:

printf($1 $2 $3 ...)

Is there a way to print all of them?

1 Answer

This will print all:

awk '{print $0}' 

And to make this long enough: this will print columns 3 to 6:

awk -v f=3 -v t=6 '{for(i=f;i<=t;i++) printf("%s%s",$i,(i==t)?"\n":OFS)}'

OFS is a built-in variable (there are 8: FS, OFS, RS, ORS, NR, NF, FILENAME, FNR) and is the output field seperator (more here).

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like