This is a test version of Biostars. For the public version, visit https://www.biostars.org.
paste columns into one line in command line

I have a txt files(very huge one) about genes, the txt file contains gene names, gene entrez_id, chrom,start, end and sequence columns. I want to put gene names, gene entrez_id, chr, start and end columns into one, and sequence will be in a new line. Basically, I want to convert txt file to fasta format with Linux command. ex: > SAMD11_148398_chr1_879534_879961 GGTTGC

I tried to use online converter, but my file is so huge, so it will be good to use command line to convert.

linux

Did you try anything? If yes, please show us, people here try to correct your code. If not, try awk.

I tried some online tools, but it failed. I was thinking use awk. And Pierre's just gave me exactly what I wanted.

I would suggest you to write an example of input and output lines. Just to let the people figure out more easily what are you expecting :)

Thanks to both of you.very efficient

Please use ADD REPLY/ADD COMMENT when responding to existing posts to keep threads logically organized.

Remember to accept one (or more) answers as correct (use the check-mark symbol against the answer).

2 answers

awk '{printf(">%s_%s_%s_%s_%s\n%s\n",$1,$2,$3,$4,$5,$6);' input.txt > out.txt

Thank you, Pierre. I used the code. It works.

Pierre, isn't it required to close } ?

Wondering how it worked for OP without closing the {.

If your input format is like ">SAMD11_148398_chr1_879534_879961 GGTTGC", then use the following command:

awk '{print $1"\n"$2}' input_file > output_file

But if your input is like "SAMD11 148398 chr1 879534 879961 GGTTGC" and you want to convert it to two lines:

>SAMD11_148398_chr1_879534_879961
GGTTGC

Use Pierre's answer!

I used Pierre's answer. It works. Thank you also.

Log in to answer this question.