How to Print All Columns Using Awk

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

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

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.