Sponsored Content
Top Forums Shell Programming and Scripting awk: Multiple search patterns & print in an one liner Post 302535435 by shamrock on Thursday 30th of June 2011 04:22:24 PM
Old 06-30-2011
Code:
gawk -F[.:] '{if ($0 ~ /pattern1/) pat1=$1; if ($0 ~ /pattern2/) pat2=$2}{if (pat1 && pat2) print pat1, pat2}' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search multiple patterns in multiple files

Hi, I have to write one script that has to search a list of numbers in certain zipped files. For eg. one file file1.txt contains the numbers. File1.txt contains 5,00,000 numbers and I have to search each number in zipped files(The number of zipped files are around 1000 each file is 5 MB) I have... (10 Replies)
Discussion started by: vsachan
10 Replies

2. Shell Programming and Scripting

awk multiple-line search and replace one-liner

Hi I am trying to search and replace a multi line pattern in a php file using awk. The pattern starts with <div id="navbar"> and ends with </div> and spans over an unknown number of lines. I need the command to be a one liner. I use the "record separator" like this : awk -v... (8 Replies)
Discussion started by: louisJ
8 Replies

3. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

4. Shell Programming and Scripting

Search for the two patterns and print everything in between

Hi all, I have a file having data: @HWUSI-EAS1727:19:6:1:3674:984:0:1#GTTAATA NTTGGGTTTTCT @HWUSI-EAS1727:19:6:1:3674:984:0:1#GTTA... NTTGGGTTTTCT @HWUSI-EAS1727:19:6:1:3674:984:0:1#.....CT NTTGGGTTTTCT I want to print everything starting from # till line ends. can you please help me how... (5 Replies)
Discussion started by: pirates.genome
5 Replies

5. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

6. Shell Programming and Scripting

awk one liner to print to end of line

Given: 1,2,whatever,a,940,sot how can i print from one particular field to the end of line? awk -F"," '{print $2 - endofline}' the delimiter just happens to be a comma "," in this case. in other cases, it could be hypens: 1---2---whatever---a---940---sot (4 Replies)
Discussion started by: SkySmart
4 Replies

7. Shell Programming and Scripting

awk Help: Filter Multiple Entry & print in one line.

AWK Gurus, data: srvhcm01 AZSCI srvhcm01 AZSDB srvhcm01 BZSDB srvhcm01 E2QDI31 srvhcm01 YPDCI srvhcm01 YPDDB srvhcm01 UV2FSCR srvhcm01 UV2FSBI srvhcm01 UV2FSXI srvhcm01 UV2FSUC srvhcm01 UV2FSEP srvhcm01 UV2FSRE srvhcm01 NASCI srvhcm01 NASDB srvhcm01 UV2FSSL srvhcm01 UV2FSDI (7 Replies)
Discussion started by: rveri
7 Replies

8. Shell Programming and Scripting

Search two patterns using awk to print the variable sum

Coins.txt: gold 1 1986 USA American Eagle gold 1 1908 Austria-Hungary Franz Josef 100 Korona silver 10 1981 USA ingot gold 1 1984 Switzerland ingot gold 1 1979 RSA Krugerrand gold 0.5 1981 RSA Krugerrand gold 0.1 1986 PRC Panda silver 1 1986 USA Liberty dollar gold 0.25 1986 USA Liberty... (2 Replies)
Discussion started by: Ramesh M
2 Replies

9. UNIX for Dummies Questions & Answers

Any awk one liner to print df output?

Hi, OS = Solaris Can anyone advise if there is a one liner to print specific output from a df -k output? Running df from a command line, it sometimes gives me 2 lines for some volume. By re-directing the output to a file, it always gives 1 line for each. Below is an example output,... (4 Replies)
Discussion started by: newbie_01
4 Replies

10. Shell Programming and Scripting

Print between multiple patterns

Hello Gurus, I have a file this Dir Path 1 Connection pool="somename"; "DataSource Name"="DS name"; Password="pwd"; User Id="uid";some other fields Dir Path2 Password="pwd2"; User id="uid2"; Connection pool="somename2"; "datasource name"="DS name2";some other fields. Under each dir... (14 Replies)
Discussion started by: sirababu
14 Replies
Bio::Tools::SeqPattern(3pm)				User Contributed Perl Documentation			       Bio::Tools::SeqPattern(3pm)

NAME
Bio::Tools::SeqPattern - represent a sequence pattern or motif SYNOPSIS
use Bio::Tools::SeqPattern; my $pat1 = 'T[GA]AA...TAAT'; my $pattern1 = Bio::Tools::SeqPattern->new(-SEQ =>$pat1, -TYPE =>'Dna'); my $pat2 = '[VILM]R(GXX){3,2}...[^PG]'; my $pattern2 = Bio::Tools::SeqPattern->new(-SEQ =>$pat2, -TYPE =>'Amino'); DESCRIPTION
Bio::Tools::SeqPattern module encapsulates generic data and methods for manipulating regular expressions describing nucleic or amino acid sequence patterns (a.k.a, "motifs"). Bio::Tools::SeqPattern is a concrete class that inherits from Bio::Seq. This class grew out of a need to have a standard module for doing routine tasks with sequence patterns such as: -- Forming a reverse-complement version of a nucleotide sequence pattern -- Expanding patterns containing ambiguity codes -- Checking for invalid regexp characters -- Untainting yet preserving special characters in the pattern Other features to look for in the future: -- Full pattern syntax checking -- Conversion between expanded and condensed forms of the pattern MOTIVATIONS
A key motivation for Bio::Tools::SeqPattern is to have a way to generate a reverse complement of a nucleotide sequence pattern. This makes possible simultaneous pattern matching on both sense and anti-sense strands of a query sequence. In principle, one could do such a search more inefficiently by testing against both sense and anti-sense versions of a sequence. It is entirely equivalent to test a regexp containing both sense and anti-sense versions of the *pattern* against one copy of the sequence. The latter approach is much more efficient since: 1) You need only one copy of the sequence. 2) Only one regexp is executed. 3) Regexp patterns are typically much smaller than sequences. Patterns can be quite complex and it is often difficult to generate the reverse complement pattern. The Bioperl SeqPattern.pm addresses this problem, providing a convenient set of tools for working with biological sequence regular expressions. Not all patterns have been tested. If you discover a pattern that is not handled properly by Bio::Tools::SeqPattern.pm, please send me some email (sac@bioperl.org). Thanks. OTHER FEATURES
Extended Alphabet Support This module supports the same set of ambiguity codes for nucleotide sequences as supported by Bio::Seq. These ambiguity codes define the behavior or the expand method. ------------------------------------------ Symbol Meaning Nucleic Acid ------------------------------------------ A A (A)denine C C (C)ytosine G G (G)uanine T T (T)hymine U U (U)racil M A or C a(M)ino group R A or G pu(R)ine W A or T (W)eak bond S C or G (S)trong bond Y C or T p(Y)rimidine K G or T (K)eto group V A or C or G H A or C or T D A or G or T B C or G or T X G or A or T or C N G or A or T or C . G or A or T or C ------------------------------------------ Symbol Meaning ------------------------------------------ A Alanine C Cysteine D Aspartic Acid E Glutamic Acid F Phenylalanine G Glycine H Histidine I Isoleucine K Lysine L Leucine M Methionine N Asparagine P Proline Q Glutamine R Arginine S Serine T Threonine V Valine W Tryptophan Y Tyrosine B Aspartic Acid, Asparagine Z Glutamic Acid, Glutamine X Any amino acid . Any amino acid Multiple Format Support Ultimately, this module should be able to build SeqPattern.pm objects using a variety of pattern formats such as ProSite, Blocks, Prints, GCG, etc. Currently, this module only supports patterns using a grep-like syntax. USAGE
A simple demo script called seq_pattern.pl is included in the examples/ directory of the central Bioperl distribution. SEE ALSO
Bio::Seq - Lightweight sequence object. 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@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists 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
Steve Chervitz, sac-at-bioperl.org COPYRIGHT
Copyright (c) 1997-8 Steve Chervitz. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. new Title : new Usage : my $seqpat = Bio::Tools::SeqPattern->new(); Purpose : Verifies that the type is correct for superclass (Bio::Seq.pm) : and calls superclass constructor last. Returns : n/a Argument : Parameters passed to new() Throws : Exception if the pattern string (seq) is empty. Comments : The process of creating a new SeqPattern.pm object : ensures that the pattern string is untained. See Also : Bio::Root::Root::new, Bio::Seq::_initialize alphabet_ok Title : alphabet_ok Usage : $mypat->alphabet_ok; Purpose : Checks for invalid regexp characters. : Overrides Bio::Seq::alphabet_ok() to allow : additional regexp characters ,.*()[]<>{}^$ : in addition to the standard genetic alphabet. : Also untaints the pattern and sets the sequence : object's sequence to the untained string. Returns : Boolean (1 | 0) Argument : n/a Throws : Exception if the pattern contains invalid characters. Comments : Does not call the superclass method. : Actually permits any alphanumeric, not just the : standard genetic alphabet. expand Title : expand Usage : $seqpat_object->expand(); Purpose : Expands the sequence pattern using special ambiguity codes. Example : $pat = $seq_pat->expand(); Returns : String containing fully expanded sequence pattern Argument : n/a Throws : Exception if sequence type is not recognized : (i.e., is not one of [DR]NA, Amino) See Also : "Extended Alphabet Support", _expand_pep(), _expand_nuc() _expand_pep Title : _expand_pep Usage : n/a; automatically called by expand() Purpose : Expands peptide patterns Returns : String (the expanded pattern) Argument : String (the unexpanded pattern) Throws : n/a See Also : expand(), _expand_nuc() _expand_nuc Title : _expand_nuc Purpose : Expands nucleotide patterns Returns : String (the expanded pattern) Argument : String (the unexpanded pattern) Throws : n/a See Also : expand(), _expand_pep() revcom Title : revcom Usage : revcom([1]); Purpose : Forms a pattern capable of recognizing the reverse complement : version of a nucleotide sequence pattern. Example : $pattern_object->revcom(); : $pattern_object->revcom(1); ## returns expanded rev complement pattern. Returns : Object reference for a new Bio::Tools::SeqPattern containing : the revcom of the current pattern as its sequence. Argument : (1) boolean (optional) (default= false) : true : expand the pattern before rev-complementing. : false: don't expand pattern before or after rev-complementing. Throws : Exception if called for amino acid sequence pattern. Comments : This method permits the simultaneous searching of both : sense and anti-sense versions of a nucleotide pattern : by means of a grep-type of functionality in which any : number of patterns may be or-ed into the recognition : pattern. : Overrides Bio::Seq::revcom() and calls it first thing. : The order of _fixpat() calls is critical. See Also : Bio::Seq::revcom, "_fixpat_1", "_fixpat_2", "_fixpat_3", "_fixpat_4", "_fixpat_5" backtranslate Title : backtranslate Usage : backtranslate(); Purpose : Produce a degenerate oligonucleotide whose translation would produce : the original protein motif. Example : $pattern_object->backtranslate(); Returns : Object reference for a new Bio::Tools::SeqPattern containing : the reverse translation of the current pattern as its sequence. Throws : Exception if called for nucleotide sequence pattern. _fixpat_1 Title : _fixpat_1 Usage : n/a; called automatically by revcom() Purpose : Utility method for revcom() : Converts all {7,5} --> {5,7} (Part I) : and [T^] --> [^T] (Part II) : and *N --> N* (Part III) Returns : String (the new, partially reversed pattern) Argument : String (the expanded pattern) Throws : n/a See Also : revcom() _fixpat_2 Title : _fixpat_2 Usage : n/a; called automatically by revcom() Purpose : Utility method for revcom() : Converts all {5,7}Y ---> Y{5,7} : and {10,}. ---> .{10,} Returns : String (the new, partially reversed pattern) Argument : String (the expanded, partially reversed pattern) Throws : n/a See Also : revcom() _fixpat_3 Title : _fixpat_3 Usage : n/a; called automatically by revcom() Purpose : Utility method for revcom() : Converts all {5,7}(XXX) ---> (XXX){5,7} Returns : String (the new, partially reversed pattern) Argument : String (the expanded, partially reversed pattern) Throws : n/a See Also : revcom() _fixpat_4 Title : _fixpat_4 Usage : n/a; called automatically by revcom() Purpose : Utility method for revcom() : Converts all {5,7}[XXX] ---> [XXX]{5,7} Returns : String (the new, partially reversed pattern) Argument : String (the expanded, partially reversed pattern) Throws : n/a See Also : revcom() _fixpat_5 Title : _fixpat_5 Usage : n/a; called automatically by revcom() Purpose : Utility method for revcom() : Converts all *[XXX] ---> [XXX]* : and *(XXX) ---> (XXX)* Returns : String (the new, partially reversed pattern) Argument : String (the expanded, partially reversed pattern) Throws : n/a See Also : revcom() _fixpat_6 Title : _fixpat_6 Usage : n/a; called automatically by revcom() Purpose : Utility method for revcom() : Converts all ?Y{5,7} ---> Y{5,7}? : and ?(XXX){5,7} ---> (XXX){5,7}? : and ?[XYZ]{5,7} ---> [XYZ]{5,7}? Returns : String (the new, partially reversed pattern) Argument : String (the expanded, partially reversed pattern) Throws : n/a See Also : revcom() str Title : str Usage : $obj->str($newval) Function: Returns : value of str Args : newvalue (optional) type Title : type Usage : $obj->type($newval) Function: Returns : value of type Args : newvalue (optional) FOR DEVELOPERS ONLY
Data Members Information about the various data members of this module is provided for those wishing to modify or understand the code. Two things to bear in mind: 1 Do NOT rely on these in any code outside of this module. All data members are prefixed with an underscore to signify that they are private. Always use accessor methods. If the accessor doesn't exist or is inadequate, create or modify an accessor (and let me know, too!). 2 This documentation may be incomplete and out of date. It is easy for this documentation to become obsolete as this module is still evolving. Always double check this info and search for members not described here. An instance of Bio::Tools::RestrictionEnzyme.pm is a blessed reference to a hash containing all or some of the following fields: FIELD VALUE ------------------------------------------------------------------------ _rev : The corrected reverse complement of the fully expanded pattern. INHERITED DATA MEMBERS: _seq : (From Bio::Seq.pm) The original, unexpanded input sequence after untainting. _type : (From Bio::Seq.pm) 'Dna' or 'Amino' perl v5.14.2 2012-03-02 Bio::Tools::SeqPattern(3pm)
All times are GMT -4. The time now is 01:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy