Madza Farias-Virgens
Madza Farias-Virgens

Reputation: 1061

Merge first two lines in specific column

I have multiple tab delim files where first line is 6tabsFILENAME

second line is V1 V2 V3 V4 A B FST

as in

                                                comb12.NCs.genes.fst
V1      V2      V3      V4      A       B       FST
NC_011462.1     17853   28371   CLIC6   0       0       NA
NC_011462.1     73261   121925  RUNX1   0       0       NA
NC_011462.1     631101  639557  SETD4   0       0       NA

I want to either fuse col5 line1 with col5 line2

V1      V2      V3      V4      A       B       FSTcomb12.NCs.genes.fst
NC_011462.1     17853   28371   CLIC6   0       0       NA
NC_011462.1     73261   121925  RUNX1   0       0       NA
NC_011462.1     631101  639557  SETD4   0       0       NA

I've tried (in a loop)

awk '{ORS=(NR==1?"":"\n")}1 ' file

but I get

                                                comb12.NCs.genes.fstV1  V2      V3      V4      A       B       FST
NC_011462.1     17853   28371   CLIC6   0       0       NA
NC_011462.1     73261   121925  RUNX1   0       0       NA
NC_011462.1     631101  639557  SETD4   0       0       NA

It fuses the first two lines as in line1line2

Upvotes: 1

Views: 54

Answers (2)

jas
jas

Reputation: 10865

Save the info from line 1 and then unleash it when you get to line 2. After that just let the default action print the lines as they are.

$ awk 'NR==1{f = $NF} NR==2{print $0 f} NR>2' file
V1      V2      V3      V4      A       B       FSTcomb12.NCs.genes.fst
NC_011462.1     17853   28371   CLIC6   0       0       NA
NC_011462.1     73261   121925  RUNX1   0       0       NA
NC_011462.1     631101  639557  SETD4   0       0       NA

Upvotes: 2

RavinderSingh13
RavinderSingh13

Reputation: 133518

Could you please try following too.

awk 'FNR==1{val=$1;next} FNR==2{$0=$0 val} 1' Input_file | column -t

Output will be as follows.

V1           V2      V3      V4     A  B  FSTcomb12.NCs.genes.fst
NC_011462.1  17853   28371   CLIC6  0  0  NA
NC_011462.1  73261   121925  RUNX1  0  0  NA
NC_011462.1  631101  639557  SETD4  0  0  NA

Upvotes: 2

Related Questions