Sponsored Content
Top Forums Shell Programming and Scripting Grepping multiple terms with different arguments Post 302325053 by dkozel on Friday 12th of June 2009 02:28:03 PM
Old 06-12-2009
Thank you. That works.

My apologies for likely being unclear. My initial grep statement and your first awk statement had the same output, lines containing search terms and the following three lines. It was the different number of following lines for each term that I was unable to figure out.

For other's references this can be extended to n search terms.

Code:
awk '/term1|term2|term3/ {c=(/term1/)?2:(/term2/)?3:4}c&&c--' testfile

The above will print term1 and the following 1 lines ( two lines total ), term2 and the following 2 lines (three lines total ), and term 3 and the following 3 lines ( four lines total).
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble grepping for multiple strings

I am having a heck of a time trying to write a script that will grep for multiple strings in a single file. I am really at my wits end here and I am hoping to get some feedback here. Basic information: OS: Solaris 9 Shell: KSH Oracle Database server I was trying to grep through a file... (5 Replies)
Discussion started by: thecoffeeguy
5 Replies

2. Shell Programming and Scripting

Grepping using multiple wildcards

Is there anyway you can grep using multiple wildcards? When I run the below line the results return fine; grep 12345 /usr/local/production/soccermatchplus/distributor/clients/*/out/fixtures.xml | awk -F/ '{print $8}' However ideally, I need it to grep for; grep 12345... (3 Replies)
Discussion started by: JayC89
3 Replies

3. Shell Programming and Scripting

Grepping Multiple Strings on the Same Line 'Or'

I've got this command that I've been using to find strings on the same line, say I'm doing a search for name: find . -name "*" | xargs grep -i "Doe" | grep -i "John" > output.txt This gives me every line in a file that has John and Doe in it. I'm looking to add a OR operator for the second... (5 Replies)
Discussion started by: Rally_Point
5 Replies

4. UNIX for Dummies Questions & Answers

Problems Grepping within multiple Quotes

Hello, I have a block of code (XML) that I would like to grep for certain information. The basic format of the XML is the following repeated a few hundred times, each time with a unique ID: <Identifier ID="A" NAME="John Doe" AGE="32 Years" FAMILY="4" SEX="MALE"></Identfier> I would like to... (6 Replies)
Discussion started by: jl487
6 Replies

5. Shell Programming and Scripting

grepping multiple matches in a single string

Hi All, I'm trying to grep for 3 patterns in a string of gibberish. It so happens that each line is appended by a date/time stamp and i was able to figure out how to extract only the datetime. here is the string.. i have to display tinker tailor soldier spy Please can some help... (2 Replies)
Discussion started by: Irishboy24
2 Replies

6. Shell Programming and Scripting

Grep multiple search terms with context

I have a file that is a sort library in the format: ##def title1 content1 stuff1 content2 stuff2 ##enddef ##def title2 etc.. I want to grep def and content and pull some trailing context from content so the result would look something like: (1 Reply)
Discussion started by: Moe.Wilensky
1 Replies

7. Programming

Grepping a column from multiple file

I have 20 files that look pretty much like this: 0.01 1 3822 4.97379915032e-14 4.96982253992e-09 0 0.01 3822 1 4.97379915032e-14 4.96982253992e-09 0 0.01 2 502 0.00993165137406 993.165137406 0 0.01 502 2 0.00993165137406 993.165137406 0 0.01 4 33 0.00189645523539 189.645523539 0 0.01 33 4... (5 Replies)
Discussion started by: kayak
5 Replies

8. Shell Programming and Scripting

Grep multiple terms and output to individual files

Hi all, I'll like to search a list of tems in a huge file and then output each of the terms to individual files. I know I can use grep -f list main.file to search them but how can I split the output into individual files? Thank you. (6 Replies)
Discussion started by: ivpz
6 Replies

9. Shell Programming and Scripting

Grepping multiple lines in a file

HI I have a file with output as System: cu=4 ent=0.1 mode=on cu min u s w i 0 500 0.1 0.3 0.5 0.1 1 200 0.5 0.2 0.3 0.0 I need to grep the values of following column fields u, s, w and i from each row sum them up and store in a variable..:( Please help.. (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

10. Shell Programming and Scripting

Grepping multiple strings from one column

I have 3-column tab separated data that looks like the following: act of+n-a-large+vn-tell-v 0.067427 act_com of+n+n-a-large-manufacturer-n 0.129922 act-act_com-com in+n-j+vn-pass-aux-restate-v 0.364499666667 com nmod+n-j+ns-invader-n 0.527521 act_com-com obj+n-a-j+vd-contribute-v 0.091413... (2 Replies)
Discussion started by: owwow14
2 Replies
Bio::Das::FeatureTypeI(3pm)				User Contributed Perl Documentation			       Bio::Das::FeatureTypeI(3pm)

NAME
Bio::Das::FeatureTypeI - Simple interface to Sequence Ontology feature types SYNOPSIS
# Get a Bio::Das::FeatureTypeI object from somewhere $term = $db->fetch.... # Get the name of the term $definition = $term->name; # Get the accession of the term $accession = $term->accession; # Get the definition of the term $definition = $term->definition; # Get the parents of the term, optionally filtered by relationship @parents = $term->parents($relationship); # Get the children of the term, optionally filtered by relationship @children = $term->children($relationship); # Given a parent and child, returns their relationship, or undef if # not directly related $relationship = $parent->relationship($child); # Return true if two terms are identical $match = $term1->equals($term2); # Return true if $term2 is a descendent of $term1, optionally # filtering by relationship ("isa" assumed) $match = $term1->is_descendent($term2,$relationship); # Return true if $term2 is a parent of $term1, optionally # filtering by relationship ("isa" assumed) $match = $term1->is_parent($term2,$relationship); # Return true if $term2 is equal to $term1 or if $term2 descends # from term 1 via the "isa" relationship $match = $term1->match($term2); # Create a new term de novo $term = Bio::Das::FeatureTypeI->new(-name => $name, -accession => $accession, -definition => $definition); # Add a child to a term $term1->add_child($term2,$relationship); # Delete a child from a term $term1->delete_child($term2); DESCRIPTION
Bio::Das::FeatureTypeI is an interface to the Gene Ontology Consortium's Sequence Ontology (SO). The SO, like other ontologies, is a directed acyclic graph in which a child node may have multiple parents. The relationship between parent and child is one of a list of relationships. The SO currently recognizes two relationships "isa" and "partof". The intent of this interface is to interoperate with older software that uses bare strings to represent feature types. For this reason, the interface overloads the stringify ("") and string equals (eq) operations. FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to one of the Bioperl mailing lists. Your participation is much appreciated. bioperl-l@bio.perl.org Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Lincoln Stein Email lstein@cshl.org APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ this is somehow FUBAR, implementation classes cannot successfully inherit from Bio::Das::FeatureTypeI name Title : name Usage : $string = $term->name Function: return the term for the type Returns : a string Args : none Status : Public accession Title : accession Usage : $string = $term->accession Function: return the accession number for the term Returns : a string Args : none Status : Public definition Title : definition Usage : $string = $term->definition Function: return the human-readable definition for the term Returns : a string Args : none Status : Public parents Title : parents Usage : @terms = $term->parents($relationship) Function: return parent terms Returns : list of Bio::Das::FeatureTypeI Args : none Status : Public Returns the parents for the current term, empty if there are none. An optional relationship argument will return those parents that are related via the specified relationship type. The relationship is one of "isa" or "partof". children Title : children Usage : @terms = $term->children($relationship) Function: return children terms Returns : list of Bio::Das::FeatureTypeI Args : none Status : Public Returns the children for the current term, empty if there are none. An optional relationship argument will return those children that are related via the specified relationship type. The relationship is one of "isa" or "partof". relationship Title : relationship Usage : $relationship = $parent->relationship($child) Function: return the relationship between a parent and a child Returns : one of "isa" or "partof" Args : none Status : Public This method returns the relationship between a parent and one of its immediate descendents. It can return "isa", "partof", or undef if there is not a direct parent/child relationship (kissing cousins are *not* recognized). equals Title : equals Usage : $boolean = $term1->equals($term2) Function: return true if $term1 and $term2 are the same Returns : boolean Args : second term Status : Public The two terms must be identical. In practice, this means that if term2 is a Bio::Das::FeatureI object, then its accession number must match the first term's accession number. Otherwise, if term2 is a bare string, then it must equal (in a case insensitive manner) the name of term1. NOTE TO IMPLEMENTORS: This method is defined in terms of other methods, so does not need to be implemented. is_descendent Title : is_descendent Usage : $boolean = $term1->is_descendent($term2 [,$relationship]) Function: return true of $term2 is a descendent of $term1 Returns : boolean Args : second term Status : Public This method returns true if $term2 descends from $term1. The operation traverses the tree. The traversal can be limited to the relationship type ("isa" or "partof") if desired. $term2 can be a bare string, in which case the term names will be used as the basis for term matching (see equals()). NOTE TO IMPLEMENTORS: this method is defined as the inverse of is_parent(). Do not implement it directly, but do implement is_parent(). is_parent Title : is_parent Usage : $boolean = $term1->is_parent($term2 [,$relationship]) Function: return true of $term2 is a parent of $term1 Returns : boolean Args : second term Status : Public This method returns true if $term2 is a parent of $term1. The operation traverses the tree. The traversal can be limited to the relationship type ("isa" or "partof") if desired. $term2 can be a bare string, in which case the term names will be used as the basis for term matching (see equals()). NOTE TO IMPLEMENTORS: Implementing this method will also implement is_descendent(). match Title : match Usage : $boolean = $term1->match($term2) Function: return true if $term1 equals $term2 or if $term2 is an "isa" descendent Returns : boolean Args : second term Status : Public This method combines equals() and is_descendent() in such a way that the two terms will match if they are the same or if the second term is an instance of the first one. This is also the basis of the operator overloading of eq. NOTE TO IMPLEMENTORS: This method is defined in terms of other methods and does not need to be implemented. new Title : new Usage : $term = Bio::Das::FeatureTypeI->new(@args) Function: create a new term Returns : new term Args : see below Status : Public This method creates a new Bio::Das::FeatureTypeI. Arguments: Argument Description -------- ------------ -name Name of this term -accession Accession number for the term -definition Definition of the term add_child Title : add_child Usage : $boolean = $term->add_child($term2,$relationship) Function: add a child to a term Returns : a boolean indicating success Args : new child Throws : a "cycle detected" exception Status : Public This method adds a new child to the indicated node. It may detect a cycle in the DAG and throw a "cycle detected" exception. delete_child Title : delete_child Usage : $boolean = $term->delete_child($term2); Function: delete a child of the term Returns : a boolean indicating success Args : child to be deleted Throws : a "not a child" exception Status : Public This method deletes a new child from the indicated node. It will throw an exception if the indicated child is not a direct descendent. perl v5.14.2 2012-03-02 Bio::Das::FeatureTypeI(3pm)
All times are GMT -4. The time now is 02:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy