Question: updating a cell in a file
0
gravatar for vinayjrao
2.3 years ago by
vinayjrao170
JNCASR, India
vinayjrao170 wrote:

Hello,

I was analyzing TCGA RNA Seq data and I created a file containing the patient ID, molecular subtype, and the rpkm for each gene, which looks like this -

sample     subtype     A1BG     KAT5     KRT5

Although when I prepared the file, I missed out on the headers of sample and subtype, and therefore the file looks like this -

patient1     LumA     A1BG     KAT5     KRT5

patient2     LumA     0.000358     1.02035     0.010204566

The problem is that the rpkm mentioned below each gene in the example are meant for patient1.

Is there any way for me to add two cells to the existing file, where I can mention [1,1] = sample and [1,2] = subtype?

Thanks in advance.

awk shell sed • 601 views
ADD COMMENTlink modified 2.2 years ago by Shred160 • written 2.3 years ago by vinayjrao170

Have you got to do this multiple times? If not it would be easy enough to convert it to a TSV/CSV and just manually add in a couple of blanks

ADD REPLYlink written 2.3 years ago by Joe16k

That's what I did due to the urgency, but I only need to add the first two strings (sample and subtype)

ADD REPLYlink written 2.3 years ago by vinayjrao170
0
gravatar for Shred
2.2 years ago by
Shred160
Shred160 wrote:

Use sed

sed -i '1s/^/added_text\n/' yourfile

Refers: https://superuser.com/questions/246837/how-do-i-add-text-to-the-beginning-of-a-file-in-bash

The only thing to note is the "\t" spacer between the two words needed for headers.

ADD COMMENTlink written 2.2 years ago by Shred160

Thanks, but it's not exactly what I was looking for. It adds a line to start with, whereas all I want to do is to push the first two columns down by one row. In Excel terminology, push A1 and B1 to A2 and B2 while not altering C1, D1, and so on.

ADD REPLYlink written 2.2 years ago by vinayjrao170

The same. Just add "\t" instead of text.

sed -i '1 i\\t' yourfile
ADD REPLYlink written 2.2 years ago by Shred160
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: 1577 users visited in the last hour