Add column to end of each line with ´awk´

Hi,
I have data with approximately 300 columns.
I want to add a column to the end of each column with the value "1".
Is there a way that I can do this is �awk� without having to specify each individual column.
For instance, my data looks like:

pvb 1 2 3 4 5 ....... 300
fdh 3 4 5 2 4 ...... 300
dfk 2 3 4 2 6 ...... 300

and I want to add the following value as the last column:

pvb 1 2 3 4 5 ....... 300 1
fdh 3 4 5 2 4 ...... 300 1
dfk 2 3 4 2 6 ...... 300 1

Is this possible with �awk� ??

A few questions:-

  • What have you tried so far?[*]Is awk the only option you will allow?

Robin

I have tried so far the standard

awk '{print $1.....$300 "\t" "1"}'.

However, I must do this for many and typing "$X" 300 times seemed unnecessary.
So, I wanted to learn if there is a way to put this information, as each line is uniform, in the last line automatically?
No, �awk� is not the only option I will allow for, I just thought in this case �awk� seemed to make the most sense :slight_smile:

Try

awk '{$(NF+1)=1}1' file
pvb 1 2 3 4 5 ....... 300 1
fdh 3 4 5 2 4 ...... 300 1
dfk 2 3 4 2 6 ...... 300 1
1 Like

Try using $0 instead:-

awk '{print $0 "\t" "1"}' file

Does that give you what you need?

Robin

1 Like