1

I have a tab separated file, that has 5 columns:

file1.txt
1   101 T   A   0.36
1   101 T   C   0.43
1   101 T   G   0.28
1   102 A   C   0.36

I want to print the last column twice so I want to have:

1   101 T   A   0.36 0.36
1   101 T   C   0.43 0.43
1   101 T   G   0.28 0.28
1   102 A   C   0.36 0.36

And I try:

cat file1.txt | awk -v OFS="\t" '$1=$1'| awk '{print $1,$2,$3,$4,$5,$5}'

which outputs only the last column as :

0.36
0.43
0.28
0.36

I have also tried:

awk '{print $0,$5}' file1.txt

Which printed the same : which outputs only the last column as :

0.36
0.43
0.28
0.36

When I have cut command,I can separately print out cut -f1 and cut -f2 and so on, so there is no problem with that.

I couldnt understand what is going on and wanted to ask that how can I print the last column twice?

bapors
  • 887
  • 9
  • 26

1 Answers1

2

To print the last field twice:

awk '{ $NF=$NF OFS $NF }1' OFS='\t' file

The output:

1   101 T   A   0.36    0.36
1   101 T   C   0.43    0.43
1   101 T   G   0.28    0.28
1   102 A   C   0.36    0.36
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105