Question: How to replace row with another row in linux having NA and nucleotide bases
0
gravatar for Kritika
20 months ago by
Kritika260
India
Kritika260 wrote:

I have file 1:

A1  1  NA
A1  2  NA
A1  3  NA
A1  4  A
A1  5  G
A1  6  T
A1  7  NA
A1  8  NA
A1  9  NA
A2  1  NA
A2  2  NA
A2  3  T
A2  4  NA

And file 2:

A1  4  A
A1  5  C
A1  6  T
A2  3  T

I want to replace row number 4,5,6 and 3 of A2 from file 1 with a value of 4,5,6 and 3 from file 2

Expected Output in new file3:-

 A1  1  NA
 A1  2  NA
 A1  3  NA
 A1  4  A
 A1  5  C
 A1  6  T
 A1  7  NA
 A1  8  NA
 A1  9  NA
 A2  1  NA
 A2  2  NA
 A2  3  T
 A2  4  NA

I want to try this in Linux. I tried googling but I could not find better answers.

I tried in linux.

diff file2 file1
join -a 2 file2 file1 | cut -d ' ' -f -2

But i am not getting answers

linux replace • 616 views
ADD COMMENTlink modified 20 months ago by Paul1.4k • written 20 months ago by Kritika260
0
gravatar for Paul
20 months ago by
Paul1.4k
European Union
Paul1.4k wrote:

you can use awk:

cat file2 file1 | awk '!seen[$1,$2]++' | sort -k 1V,1 -k 2n,2 > result

Output:

A1  1  NA
A1  2  NA
A1  3  NA
A1  4  A
A1  5  C
A1  6  T
A1  7  NA
A1  8  NA
A1  9  NA
A2  1  NA
A2  2  NA
A2  3  T
A2  4  NA
ADD COMMENTlink written 20 months ago by Paul1.4k

No its not working it is not making any file ! No output

ADD REPLYlink written 20 months ago by Kritika260

Hi, Are your files tab delimited? cat -T input is what result?

ADD REPLYlink written 20 months ago by Paul1.4k

its giving me what is there in file value of file1

ADD REPLYlink written 20 months ago by Kritika260

if you are try to print first column - awk '{print $1}' input - does it work? When I test my on-liner on your pasted data above it is works.

ADD REPLYlink written 20 months ago by Paul1.4k

Yes its printing the first column

ADD REPLYlink written 20 months ago by Kritika260

The above code is not making any file

ADD REPLYlink written 20 months ago by Kritika260

The columns are seperated by 2 spaces

ADD REPLYlink written 20 months ago by Kritika260
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 822 users visited in the last hour