Question: Extract and ADD text information
0
gravatar for flogin
8 days ago by
flogin80
FioCruz/Brazil
flogin80 wrote:

I have a text file with multiple segments like that:

       Sites with alignment gaps or missing data: 0
       Invariable (monomorphic) sites: 604
       Variable (polymorphic) sites: 17   (Total number of mutations: 0)
          Singleton variable sites: 0
          Parsimony informative sites: 0

          Singleton variable sites (two variants): 0
          Parsimony informative sites (two variants): 0
          Variable sites (three variants): 0
          Variable sites (four variants): 0


Fu and Li's D* test statistic: 0,00000
     Statistical significance: Not significant, P > 0.10
 Fu and Li's F* test statistic: 0,00000
     Statistical significance: Not significant, P > 0.10

And I want to extract 3 lines "Variable (polymorphic) sites\|Fu and Li's F* test statistic\|Statistical significance",But, I also want to add an information like DNA POLYMORPHISM AND FU AND LI'S TEST before the results of each analysis, generating a output like that:

DNA POLYMORPHISM
     Variable (polymorphic) sites: 17

FU AND LI'S TEST
    Fu and Li's F* test statistic: 0,00000
             Statistical significance: Not significant, P > 0.10

There is any way to do like it with grep?

text grep • 65 views
ADD COMMENTlink written 8 days ago by flogin80

There is any way to do like it with grep?

yes, show us what you have tried, and then we will help you

ADD REPLYlink written 8 days ago by Pierre Lindenbaum120k

Oh sorry, I tried that:

$grep "Input Data File\|print "DNA POLYMORPHSM"\|Variable (polymorphic) sites\|print "FU AND LI'S TEST"\|Fu and Li's F test statistic\|Statistical significance" Arch.txt

I have no idea if a print function can be used inside a list of grep patterns, the help of grep doesn't show anything about text processing during the pattern extraction.

Thanks for your attention.

ADD REPLYlink modified 8 days ago by Pierre Lindenbaum120k • written 8 days ago by flogin80
1

If you know some basic programming you can use python to read a file in and append every new line to a list.

you can then save only the elements that you want and using string slicing to further carve what you what out of each element. Python is really REALLY good with text stuff and this project would be a good learning experience and is probably not a heavy lift if you already know some bash scripting.

ADD REPLYlink written 7 days ago by brett.vanderwerff100
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: 1654 users visited in the last hour