Sponsored Content
Top Forums Shell Programming and Scripting Extract batch based on condition Post 302939053 by Don Cragun on Saturday 21st of March 2015 09:21:07 PM
Old 03-21-2015
If for some reason, you really need a way to do this only using shell built-ins, you could try something like the following with any POSIX-conforming shell:
Code:
#!/bin/ksh
IAm="${0##*/}"
Usage() {
	case "$1" in
	(2)	printf "%s: Can't read input_file: %s\n" "$IAm" "$2";;
	(4)	printf '%s: Invalid date in "|T" line: %s\n' "$IAm" "$2";;
	(5)	printf '%s: Invalid ID in ".T" line: %s\n' "$IAm" "$2";;
	(6)	printf '%s: Invalid tag: %s\n' "$IAM" "$2";;
	(7)	printf '%s: Invalid line length: %s\n' "$IAm" "$2";;
	esac >&2
	printf 'Usage: %s input_file output_file\n' "$IAm" >&2
	exit $1
}

[ $# -ne 2 ] && Usage 1
[ ! -r "$1" ] && Usage 2 "$1"
> "$2" || Usage 3 "$2"
while read -r tag data
do	case ${#tag} in
	(2)	case "$tag" in
		("|T")	[ ${#data} -ne 8 ] && Usage 4 "$tag $data"
			out="$tag $data"
			copy=0;;
		(".T")	[ "$data" = '' ] && Usage 5 "$tag"
			if [ $copy -eq 1 ]
			then	printf '%s\n%s %s\n' "$out" "$tag" "$data" > "$2"
			fi;;
		(*)	Usage 6 "$tag $data";;
		esac;;
	(17)	case "$tag" in
		(10000000000000000)
			;;
		(10*)	copy=1;;
		esac
		out=$(printf '%s\n%s' "$out" "$tag");;
	(*)	Usage 7 "$tag $data";;
	esac
done < "$1"

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract value inside <text> tag for a particular condition.

Hi All! I have obtained following output from a tool "pdftohtml" :: So, my input is as under: <text top="246" left="160" width="84" height="16" font="3">Business purpose</text> <text top="260" left="506" width="220" height="16" font="3">giving the right information and new insights... (3 Replies)
Discussion started by: parshant_bvcoe
3 Replies

2. Shell Programming and Scripting

extract xml tag based on condition

Hi All, I have a large xml file of invoices. The file looks like below: <INVOICES> <INVOICE> <NAME>Customer A</NAME> <INVOICE_NO>1234</INVOICE_NO> </INVOICE> <INVOICE> <NAME>Customer A</NAME> <INVOICE_NO>2345</INVOICE_NO> </INVOICE> <INVOICE> <NAME>Customer A</NAME>... (9 Replies)
Discussion started by: angshuman
9 Replies

3. Shell Programming and Scripting

Script to batch pdfjoin based on pdfgrep output

I have a situation in which I'm given a bunch of pdf files which are all single pages with employee ID's on an independent line. I need to collate all of the pages by employee ID. Piecemeal, I can find a particular employee ID by just using pdfgrep. I could also do something like this: find .... (3 Replies)
Discussion started by: nopposan
3 Replies

4. Shell Programming and Scripting

ksh: how to extract strings from each line based on a condition

Hi , I'm a newbie.Never worked on Unix before. I want a shell script to perform the following: I want to extract strings from each line ,based on the type of line(Nameline,Subline) and output it to another file.Below is a sample format. 2010-12-21 14:00"1"Nameline"Midterm"First Name:Jane ... (4 Replies)
Discussion started by: angie1234
4 Replies

5. Shell Programming and Scripting

Help with extract info if fulfill condition required

Input file (4 DATA record shown in this case): DATA AA0110 ACCESSION AA0110 VERSION AA0110 GI:157412239 FEATURES Location/Qualifiers length 1..1170 1..1700 /length="1170" position ... (5 Replies)
Discussion started by: perl_beginner
5 Replies

6. UNIX for Dummies Questions & Answers

Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 Replies

7. Shell Programming and Scripting

Copy down based on condition

Hello: I need to copy down some data from the previous record in to the next record based on the below conditions If position 41- 59 of the current record is same as the previous record and the value of position 62 is not equal to 1 then copy the previous records value for positions... (1 Reply)
Discussion started by: techedipro
1 Replies

8. Windows & DOS: Issues & Discussions

Batch file loop and increment value for condition

I am trying to have the below batch file do following two things: 1. only allow the values YES,yes,Y,y, or NO,no,N,n 2. increment the counter %var1 only if answer to question 2 is "y" and not able to get the syntax correct. If %var1%=1 then I am trying to display function :end. Thank you :).... (0 Replies)
Discussion started by: cmccabe
0 Replies

9. UNIX for Beginners Questions & Answers

extract file .jar from package and batch

Thank You to vbe For This Useful Post i want to extract file. jar from package and batch ? (1 Reply)
Discussion started by: moh_abaloo
1 Replies
Bio::Tree::TreeI(3pm)					User Contributed Perl Documentation				     Bio::Tree::TreeI(3pm)

NAME
Bio::Tree::TreeI - A Tree object suitable for lots of things, designed originally for Phylogenetic Trees. SYNOPSIS
# get a Bio::Tree::TreeI somehow # like from a TreeIO my $treeio = Bio::TreeIO->new(-format => 'newick', -file => 'treefile.dnd'); my $tree = $treeio->next_tree; my @nodes = $tree->get_nodes; my @leaves = $tree->get_leaf_nodes; my $root = $tree->get_root_node; DESCRIPTION
This object holds a pointer to the Root of a Tree which is a Bio::Tree::NodeI. 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 the Bioperl mailing list. 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 of the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Jason Stajich Email jason@bioperl.org CONTRIBUTORS
Aaron Mackey, amackey@virginia.edu Elia Stupka, elia@fugu-sg.org Sendu Bala, bix@sendu.me.uk APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ get_nodes Title : get_nodes Usage : my @nodes = $tree->get_nodes() Function: Return list of Tree::NodeI objects Returns : array of Tree::NodeI objects Args : (named values) hash with one value order => 'b|breadth' first order or 'd|depth' first order get_root_node Title : get_root_node Usage : my $node = $tree->get_root_node(); Function: Get the Top Node in the tree, in this implementation Trees only have one top node. Returns : Bio::Tree::NodeI object Args : none number_nodes Title : number_nodes Usage : my $size = $tree->number_nodes Function: Find the number of nodes in the tree. Returns : int Args : none total_branch_length Title : total_branch_length Usage : my $size = $tree->total_branch_length Function: Returns the sum of the length of all branches Returns : integer Args : none height Title : height Usage : my $height = $tree->height Function: Gets the height of tree - this LOG_2($number_nodes) WARNING: this is only true for strict binary trees. The TreeIO system is capable of building non-binary trees, for which this method will currently return an incorrect value!! Returns : integer Args : none id Title : id Usage : my $id = $tree->id(); Function: An id value for the tree Returns : scalar Args : score Title : score Usage : $obj->score($newval) Function: Sets the associated score with this tree This is a generic slot which is probably best used for log likelihood or other overall tree score Returns : value of score Args : newvalue (optional) get_leaf_nodes Title : get_leaf_nodes Usage : my @leaves = $tree->get_leaf_nodes() Function: Returns the leaves (tips) of the tree Returns : Array of Bio::Tree::NodeI objects Args : none Methods for associating Tag/Values with a Tree These methods associate tag/value pairs with a Tree set_tag_value Title : set_tag_value Usage : $tree->set_tag_value($tag,$value) $tree->set_tag_value($tag,@values) Function: Sets a tag value(s) to a tree. Replaces old values. Returns : number of values stored for this tag Args : $tag - tag name $value - value to store for the tag add_tag_value Title : add_tag_value Usage : $tree->add_tag_value($tag,$value) Function: Adds a tag value to a tree Returns : number of values stored for this tag Args : $tag - tag name $value - value to store for the tag remove_tag Title : remove_tag Usage : $tree->remove_tag($tag) Function: Remove the tag and all values for this tag Returns : boolean representing success (0 if tag does not exist) Args : $tag - tagname to remove remove_all_tags Title : remove_all_tags Usage : $tree->remove_all_tags() Function: Removes all tags Returns : None Args : None get_all_tags Title : get_all_tags Usage : my @tags = $tree->get_all_tags() Function: Gets all the tag names for this Tree Returns : Array of tagnames Args : None get_tag_values Title : get_tag_values Usage : my @values = $tree->get_tag_values($tag) Function: Gets the values for given tag ($tag) Returns : Array of values or empty list if tag does not exist Args : $tag - tag name has_tag Title : has_tag Usage : $tree->has_tag($tag) Function: Boolean test if tag exists in the Tree Returns : Boolean Args : $tag - tagname perl v5.14.2 2012-03-02 Bio::Tree::TreeI(3pm)
All times are GMT -4. The time now is 07:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy