Sponsored Content
Top Forums Shell Programming and Scripting Extracting the tag name from an xml file Post 302925517 by ongoto on Monday 17th of November 2014 04:09:33 PM
Old 11-17-2014
grep is a good idea.

Try this on some real data...
Code:
#!/bin/bash
#
# tags.sh

if [ ! $1 ]; then 
    echo "usage: `basename $0` <filename.xml> [output file]"
    exit 1
fi

tag_list=( $(grep -o -e "^\s*<\w.\w*>$" $1 | tr -d ' <>' | sed s/^n://g | sort -u ))
printf "\n%s%s\n" "tag_name=\"" "${tag_list[*]}\""

# Append to outfile
if [ $2 ]; then
    touch $2
    printf "%s:\n%s%s\n\n" "$1" "tag_name=\"" "${tag_list[*]}\"" >> $2
fi

### eof #

output
--------
$ tags.sh filename.xml
tag_name="tag_name1 tag_name2"

Last edited by ongoto; 11-17-2014 at 07:28 PM.. Reason: monkeying with regex
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting XML Tag Contents

Hi Jean I require your help in writing a shell script. Iam zero in Unix programming. I have a large file about 400 MB of data, which contains about 50000 XML messages seperated by a Tab, I think. I need to extract only 4 values from each XML message and write it onto a new file. Please help me... (2 Replies)
Discussion started by: pk_eee
2 Replies

2. Shell Programming and Scripting

Extracting tag values from XML using perl

Hi All, I'm trying to extract the values for the 'src' and 'alt' tags within an xml file. In the files that I'm searching, the tags are always enclosed within an 'img' tag. Typically: <img src="diwiz01.gif" width="576" height="254" alt="Out-of-process and In-process COM Objects"><bookmark... (3 Replies)
Discussion started by: Steve_altius
3 Replies

3. Shell Programming and Scripting

Extracting the value of an attribute tag from XML

Greetings, I am very new to the UNIX shell scripting and would like to learn. However, I am currently stuck on how to process the below sample of code from an XML file using UNIX comands: <ATTRIBUTE NAME="Memory" VALUE="512MB"/> <ATTRIBUTE NAME="CPU Speed" VALUE="3.0GHz"/> <ATTRIBUTE... (5 Replies)
Discussion started by: JesterMania
5 Replies

4. Shell Programming and Scripting

XML tag replacement from different XML file

We have 2 XML file 1. ORIGINAL.xml file and 2. ATTRIBUTE.xml files, In the ORIGINAL.xml we need some modification as <resourceCode>431048</resourceCode>under <item type="Manufactured"> tag - we need to grab the 431048 value from tag and pass it to database table in unix shell script to find the... (0 Replies)
Discussion started by: balrajg
0 Replies

5. Shell Programming and Scripting

Extracting the value of an middle attribute tag from XML

Hi All, Please help me out in resolving this.. <secondTag enabled='true' processName='test1' pidFile='/tmp/test1.pid' /> From the above tag, I'm trying to retrieve the value of enabled and pidFile attributes by means of processName attribute. Would be thankful in resolving this..... (5 Replies)
Discussion started by: mjavalkar
5 Replies

6. Shell Programming and Scripting

How to retrieve the value from XML tag whose end tag is in next line

Hi All, Find the following code: <Universal>D38x82j1JJ </Universal> I want to retrieve the value of <Universal> tag as below: Please help me. (3 Replies)
Discussion started by: mjavalkar
3 Replies

7. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

8. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

9. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

10. UNIX for Beginners Questions & Answers

Grepping multiple XML tag results from XML file.

I want to write a one line script that outputs the result of multiple xml tags from a XML file. For example I have a XML file which has below XML tags in the file: <EMAIL>***</EMAIL> <CUSTOMER_ID>****</CUSTOMER_ID> <BRANDID>***</BRANDID> Now I want to grep the values of all these specified... (1 Reply)
Discussion started by: shubh752
1 Replies
Bio::SeqIO::agave(3pm)					User Contributed Perl Documentation				    Bio::SeqIO::agave(3pm)

NAME
Bio::SeqIO::agave - AGAVE sequence output stream. SYNOPSIS
It is probably best not to use this object directly, but rather go through the SeqIO handler system. Go: $in = Bio::SeqIO->new('-file' => "$file_in", '-format' => 'EMBL'); $out = Bio::SeqIO->new('-file' => ">$file_out", '-format' => 'AGAVE'); while (my $seq = $in->next_seq){ $out->write_seq($seq); } DESCRIPTION
This object can transform Bio::Seq objects to agave xml file and vice-versa. I (Simon) coded up this module because I needed a parser to extract data from AGAVE xml to be utitlized by the GenQuire genome annotation system (See http://www.bioinformatics.org/Genquire). ***NOTE*** At the moment, not all of the tags are implemented. In general, I followed the output format for the XEMBL project http://www.ebi.ac.uk/xembl/ 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 - Simon K. Chan Email: APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ _process Title : _process Usage : $self->_process Function : Parses the agave xml file. Args : None. Returns : Nothing. Note : Method(s) that call(s) this method : _initialize Method(s) that this method calls : _process_sciobj FIRST/START sub. _process_sciobj Title : _process_sciobj Usage : $self->_process_sciobj Function : Parses the data between the <sciobj></sciobj> tags. Args : The string that holds the attributes for <sciobj>. Returns : Data structure holding the values parsed between the <sciobj></sciobj> tags. Note : Method(s) that call(s) this method : _process Method(s) that this method calls : _helper_store_attribute_list , _process_contig _process_contig Title : _process_contig Usage : $self->_process_contig Function : Parses the data between the <contig></contig> tags. Args : 2 scalars: - reference to a scalar holding the line to be parsed. - scalar holding the attributes for the <contig> tag to be parsed. Returns : Data structure holding the values parsed between the <contig></contig> tags. Note : Method(s) that call(s) this method : _process_sciobj Method(s) that this method calls : _helper_store_attribute_list, _one_tag , _process_fragment_order _process_fragment_order Title : _process_fragment_order Usage : $self->_process_fragment_order Function : Parses the data between the <fragment_order></fragment_order> tags. Args : 2 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the <fragment_order> data. Returns : Nothing. Note : Method(s) that call(s) this method : _process_contig Method(s) that this method calls : _helper_store_attribute_list , _process_fragment_orientation _process_fragment_orientation Title : _process_fragment_orientation Usage : $self->_process_fragment_orientation Function : Parses the data between the <fragment_orientation> and </fragment_orientation> tags. Args : 2 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the <fragment_orientation> data. Returns : Nothing. Note : Method(s) that call(s) this method : _process_fragment_order Method(s) that this method calls : _helper_store_attribute_list , _process_bio_sequence _process_bio_sequence Title : _process_bio_sequence Usage : $self->_process_bio_sequence Function : Parses the data between the <bio_sequence></bio_sequence> tags. Args : 2 scalars: - reference to a scalar holding the value of the line to be parsed. - scalar holding the value of the attributes for <bio_sequence> Returns : data structure holding the values between <bio_sequence></bio_sequence> Note : Method(s) that call(s) this method : _process_fragment_orientation Method(s) that this method calls : _helper_store_attribute_list , _one_tag , _question_mark_tag , _star_tag , _process_alt_ids , _process_xrefs , _process_sequence_map _process_xrefs Title : _process_xrefs Usage : $self->_process_xrefs Function : Parse the data between the <xrefs></xrefs> tags. Args : reference to a scalar holding the value of the line to be parsed. Return : Nothing. Note : Method(s) that call(s) this method: _process_bio_sequence Method(s) that this method calls: _one_tag , _process_xref _process_xref Title : _process_xref Usage : $self->_process_xref Function : Parses the data between the <xref></xref> tags. Args : 2 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the <xref> data. Returns : Nothing. Note : Method(s) that call(s) this method : _process_xrefs (note the 's' in 'xrefs') Method(s) that this method calls : _helper_store_attribute_list , _star_tag _process_sequence_map Title : _process_sequence_map Usage : $self->_process_sequence_map Function : Parses the data between the <sequence_map></sequence_map> tags. Args : Reference to scalar holding the line to be parsed. Returns : Data structure that holds the values that were parsed. Note : Method(s) that call(s) this method : _process_bio_sequence Method(s) that this method calls : _helper_store_attribute_list , _question_mark_tag , _process_annotations _process_annotations Title : _process_annotations Usage : $self->_process_annotations Function : Parse the data between the <annotations></annotations> tags. Args : Reference to scalar holding the line to be parsed. Returns : Data structure that holds the values that were parsed. Note : Method(s) that call(s) this method : _process_sequence_map Method(s) that this method calls : _process_seq_feature _process_seq_feature Title : _process_seq_feature Usage : $self->_process_seq_feature Function : Parses the data between the <seq_feature></seq_feature> tag. Args : 2 scalars: - Reference to scalar holding the line to be parsed. - Scalar holding the attributes for <seq_feature>. Returns : Data structure holding the values parsed. Note : Method(s) that call(s) this method: _process_annotations Method(s) that this method calls: _helper_store_attribute_list , _process_classification , _question_mark_tag , _one_tag , _process_evidence , _process_qualifier , _process_seq_feature , _process_related_annot _process_qualifier Title : _process_qualifier Usage : $self->_process_qualifier Function : Parse the data between the <qualifier></qualifier> tags. Args : 2 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the <qualifer> data. Returns : Nothing. Note : Method(s) that call(s) this method : _process_seq_feature Method(s) that this method calls : _star_tag _process_classification Title : _process_classification Usage : $self->_process_classification Function: Parse the data between the <classification></classification> tags. Args : 2 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the <qualifer> data. Returns : Nothing. Note : Method(s) that call(s) this method: _process_seq_feature Method(s) that this method calls: _helper_store_attribute_list , _question_mark_tag , _star_tag, _process_evidence _tag_processing_helper Title : _tag_processing_helper Usage : $self->_tag_processing_helper Function : Stores the tag value within the data structure. Also calls _helper_store_attribute_list to store the attributes and their values in the data structure. Args : 5 scalars: - Scalar holding the value of the attributes - Reference to a data structure to store the data for <$tag_name> - Scalar holding the tag name. - Scalar holding the value of the tag. - Scalar holding the value of either 'star', 'plus', or 'question mark' which specifies what type of method called this method. Returns : Nothing. Note : Method(s) that call(s) this method: Method(s) that this method calls: _helper_store_attribute_list _one_tag Title : _one_tag Usage : $self->_one_tag Function : A method to store data from tags that occurs just once. Args : 2 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the data for <$tag_name> Returns : Nothing. Note : Method(s) that call(s) this method : many Method(s) that this method calls : _tag_processing_helper _question_mark_tag Title : _question_mark_tag Usage : $self->_question_mark_tag Function : Parses values from tags that occurs zero or one time. ie: tag_name? Args : 3 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the data for <$tag_name> - scalar holding the name of the tag. Returns : Nothing. Note : Method(s) that call(s) this method : many. Method(s) that this method calls : _tag_processing_helper _star_tag Title : _star_tag Usage : $self->_star_tag Function : Parses values from tags that occur zero or more times. ie: tag_name* Args : 3 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the data for <$tag_name> - scalar holding the name of the tag. Returns : Nothing. Note : Method(s) that call(s) this method : many. Method(s) that this method calls : _tag_processing_helper _plus_tag Title : _plus_tag Usage : $self->_plus_tag Function : Handles 'plus' tags (tags that occur one or more times). tag_name+ Args : 3 scalars: - reference to a scalar holding the value of the line to be parsed. - reference to a data structure to store the data for <$tag_name> - scalar holding the name of the tag. Returns : Nothing. Note : Method(s) that call(s) this method : many. Method(s) that this method calls : _star_tag _helper_store_attribute_list Title : _helper_store_attribute_list Usage : $self->_helper_store_attribute_list Function : A helper method used to store the attributes from the tags into the data structure. Args : 2 scalars: - scalar holding the attribute values to be parsed. - reference to a data structure to store the data between the 2 tags. Returns : Nothing. Note : Method(s) that call(s) this method : Many. Method(s) that this method call(s) : None. _store_seqs Title : _store_seqs Usage : $self->_store_seqs Function : This method is called once in the life time of the script. It stores the data parsed from the agave xml file into the Bio::Seq object. Args : None. Returns : Nothing. Note : Method(s) that call(s) this method : next_seq Method(s) that this method calls : None. next_seq Title : next_seq Usage : $seq = $stream->next_seq() Function : Returns the next sequence in the stream. Args : None. Returns : Bio::Seq object Method is called from the script. Method(s) that this method calls: _store_seqs (only once throughout the life time of script execution). next_primary_seq Title : next_primary_seq Usage : $seq = $stream->next_primary_seq() Function: returns the next primary sequence (ie no seq_features) in the stream Returns : Bio::PrimarySeq object Args : NONE write_seq Title : write_seq Usage : Not Yet Implemented! $stream->write_seq(@seq) Function: writes the $seq object into the stream Returns : 1 for success and 0 for error Args : Bio::Seq object _write_each_record Title : _write_each_record Usage : $agave->_write_each_record( $seqI ) Function: change data into agave format Returns : NONE Args : Bio::SeqI object _write_seqfeature Usage : $agave->_write_each_record( $seqfeature, $write ) Function: change seeqfeature data into agave format Returns : NONE Args : Bio::SeqFeature object and XML::writer object _filehandle Title : _filehandle Usage : $obj->_filehandle($newval) Function: Example : Returns : value of _filehandle Args : newvalue (optional) throw Title : throw Usage : $self->throw; Function : Throw's error message. Calls SeqIO's throw method. Args : Array of string(s), holding error message(s). Returns : Nothing. Note : Method(s) that call(s) this method: many. Method(s) that this method calls: Bio::SeqIO's throw method. perl v5.14.2 2012-03-02 Bio::SeqIO::agave(3pm)
All times are GMT -4. The time now is 01:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy