perl or the other scripts converting text file
1
0
Entering edit mode
7.9 years ago

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

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

ADD REPLY
0
Entering edit mode

This is not a homework assignment.

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
1
Entering edit mode

This is what people with homework assignment would say!

ADD REPLY
0
Entering edit mode

input.txt

#1 #2 #3

contig1.1 none A.fa

contig2.1 yes B.fa

contig5.1 none C.fa

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
2
Entering edit mode
7.9 years ago

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.

ADD COMMENT

Login before adding your answer.

Traffic: 1609 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