Extract and ADD text information
0
0
Entering edit mode
5.5 years ago
flogin ▴ 280

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?

grep text • 1.0k views
ADD COMMENT
0
Entering edit mode

There is any way to do like it with grep?

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

ADD REPLY
0
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY

Login before adding your answer.

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