Question: perl or the other scripts converting text file
0
gravatar for nakanomasayuki265
2.2 years ago by
nakanomasayuki26550 wrote:

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 • 653 views
ADD COMMENTlink modified 2.2 years ago by Alex Reynolds28k • written 2.2 years ago by nakanomasayuki26550
1

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

ADD REPLYlink written 2.2 years ago by Brian Bushnell16k

This is not a homework assignment.

ADD REPLYlink written 2.2 years ago by nakanomasayuki26550
1

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 REPLYlink written 2.2 years ago by Brian Bushnell16k
1

This is what people with homework assignment would say!

ADD REPLYlink written 2.2 years ago by Rob90

input.txt

#1 #2 #3

contig1.1 none A.fa

contig2.1 yes B.fa

contig5.1 none C.fa

ADD REPLYlink modified 2.2 years ago • written 2.2 years ago by nakanomasayuki26550

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 REPLYlink written 2.2 years ago by Charles Plessy2.6k
2
gravatar for Alex Reynolds
2.2 years ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

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 COMMENTlink modified 2.2 years ago • written 2.2 years ago by Alex Reynolds28k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1057 users visited in the last hour