This is a test version of Biostars. For the public version, visit https://www.biostars.org.
perl or the other scripts converting text file

There is a tab-delimited file input.txt, and it looks like the following.

#1 #2 #3
contig1.1 none A.fa
contig2.1 yes B.fa
contig5.1 none C.fa

There is a space delimited input2.txt file,

Input text =#1  I = #2 > #3

Based on this I would like to create the following output (space delimiter). Could you tell me about perl and ruby scripts that can create this? A script that can handle any number of input.txt columns is helpful.

Input text=contig1.1  I=none  >A.fa

Input text=contig2.1  I=yes  >B.fa

Input text=contig5.1  I=none  >C.fa
sequence

input.txt

#1 #2 #3

contig1.1 none A.fa

contig2.1 yes B.fa

contig5.1 none C.fa

This sounds like a homework assignment. If so, please state that up front.

In that case, it would be helpful to state what kind of data you have, what experiment you are doing, and what you are trying to accomplish. You initial post leaves readers completely clueless as to these details, which hampers their ability to help you.

This is what people with homework assignment would say!

You can also do it in plain shell:

$ cat input.txt | while read X Y Z ; do echo "Input text=$X  I=$Y > $Z" ; done
Input text=contig1.1  I=none > A.fa
Input text=contig2.1  I=yes > B.fa
Input text=contig5.1  I=none > C.fa

The same pattern is particularly handy to execute a bunch of commands using a template.

1 answer

It is not immediately clear why you would need a second file. To solve your problem as described, you could just use the first file and run it through awk:

$ awk '{ print "Input text="$1" I="$2" > "$3 }' input.txt > output.txt

See those $1, $2, etc.? Those are placeholders for the value of whatever fields/columns you pipe into awk, so that you can process them and reprint them however you like, line by line.

Log in to answer this question.