updating a cell in a file
1
0
Entering edit mode
6.1 years ago
vinayjrao ▴ 250

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 • 1.3k views
ADD COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
6.1 years ago
Shred ★ 1.4k

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 COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

sed -i '1 i\\t' yourfile
ADD REPLY

Login before adding your answer.

Traffic: 2937 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6