Print each column 3 times

Hi All,

I have a file with more than 2000 columns and I would like to print each column 3 times, so that I will get a file like col1 col1 col1 col2 col2 col2 ........coln coln coln.

I have tried the following code:

awk '{for(i=1; i<=NF; i++) {s=s FS $i,$i,$i} print s;s=""}' input > output

But it didn't work. If anyone can help me in this regard.

Your answers are highly appreciated.

Regards
Fredrick.

---------- Post updated at 06:09 PM ---------- Previous update was at 05:58 PM ----------

Sorry, I got the idea. Here is the code

awk '{for(i=1; i<=NF; i++) {s=s FS $i FS $i FS $i} print s;s=""}' input > output

If someone can help me with some better code, you are always welcome.

Thanks & regards
Fredrick.

How about using sed Assuming columns are blank space separated:-

sed -e 's/[^ ]*/& & &/g' input > output

Many awk versions have limited fields.
Set an RS=" " in the beginning, and each field becomes a record.

awk '{print $1,$1,$1}' RS=" " ORS=" " input

But this only works with one line.
The previous post is best.