This is a test version of Biostars. For the public version, visit https://www.biostars.org.
updating a cell in a file

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.

shell awk sed

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

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

1 answer

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.

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.

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

sed -i '1 i\\t' yourfile

Log in to answer this question.