Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Editing strings within lines of file Post 302608711 by pawannoel on Sunday 18th of March 2012 11:00:52 AM
Old 03-18-2012
OK ... the input for example is :
Code:
"029/A" 
 "029/a" 
 "29 /A" 
 "029/M" 
 "029/m"

and the desired output should be
Code:
29
29
29
2.4
2.4

Thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting the lines between 2 strings of a file

Hi, I have a sql file and i need to extract the table names used in the sql file using a unix script. If i can extract the lines between the keywords 'FROM' and 'WHERE' in the file, my job is done. can somebody tell me how to do this using a shell script. If u can just let me know, how to... (2 Replies)
Discussion started by: babloo
2 Replies

2. UNIX for Dummies Questions & Answers

Counting no of lines between two strings in a file

Hi all, I'm very very new to UNIX and AWK world.Please help me in finding a solution for my problem. I'm having a file like this ----------------------------------------------------------------- ~Version Information VERS. 2.0: CWLS log ASCII Standard -VERSION 2.0 WRAP. ... (4 Replies)
Discussion started by: santyshyam
4 Replies

3. Shell Programming and Scripting

Adding strings to lines in a file

Hi all, I have a positional text file that comes from some source application. Before it is processed by destination application I have to add some header (suffix) to every record(line) in the file. e.g. Actual File ............... AccountDetails AcNO Name Amount 1234 John 26578 5678... (3 Replies)
Discussion started by: sharath160
3 Replies

4. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

5. Shell Programming and Scripting

Extract strings from multiple lines into one file -

input file Desired csv output gc_type, date/time, milli secs af, Mar 17 13:09:04 2011, 144.596 af, Mar 20 00:37:37 2011, 144.242 af, ar 20 21:30:59 2011, 108.518 Hi All, Any help in acheiving the above would be appreciated. I would like to parse through lines within one file and... (5 Replies)
Discussion started by: satish.vampire
5 Replies

6. Shell Programming and Scripting

awk how to search strings within a file from two different lines

Hi, i would really appreciate any help anyone can give with the following info. Thanks in advance. I need to run a search on a file that contains thousands of trades, each trade is added into the file in blocks of 25 lines. i know the search has to take place between a time stamp specified... (4 Replies)
Discussion started by: sp3arsy
4 Replies

7. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

8. Shell Programming and Scripting

Egrep strings on different lines in file

test.txt: appleboy orangeletter sweetdeal catracer conducivelot I want to only grep out lines that contain "appleboy" AND "sweetdeal". however, the closest thing to this that i can think of is this: cat test.txt | egrep "appleboy|sweetdeal" problem is this only searches for all... (9 Replies)
Discussion started by: SkySmart
9 Replies

9. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

10. Shell Programming and Scripting

Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines

I have a bunch of file numbers in the file 'test': I'm trying the above command to change all the instances of "H" to "Na+" in the file testsds.pdb at the line numbers indicated in the file 'test'. I've tried the following and various similar alternatives but nothing is working: cat test |... (3 Replies)
Discussion started by: crunchgargoyle
3 Replies
XML::Mini::Document(3pm)				User Contributed Perl Documentation				  XML::Mini::Document(3pm)

NAME
XML::Mini::Document - Perl implementation of the XML::Mini Document API. SYNOPSIS
use XML::Mini::Document; use Data::Dumper; ###### PARSING XML ####### # create a new object my $xmlDoc = XML::Mini::Document->new(); # init the doc from an XML string $xmlDoc->parse($XMLString); # You may use the toHash() method to automatically # convert the XML into a hash reference my $xmlHash = $xmlDoc->toHash(); print Dumper($xmlHash); # You can also manipulate the elements like directly, like this: # Fetch the ROOT element for the document # (an instance of XML::Mini::Element) my $xmlRoot = $xmlDoc->getRoot(); # play with the element and its children # ... my $topLevelChildren = $xmlRoot->getAllChildren(); foreach my $childElement (@{$topLevelChildren}) { # ... } ###### CREATING XML ####### # Create a new document from scratch my $newDoc = XML::Mini::Document->new(); # This can be done easily by using a hash: my $h = { 'spy' => { 'id' => '007', 'type' => 'SuperSpy', 'name' => 'James Bond', 'email' => 'mi5@london.uk', 'address' => 'Wherever he is needed most', }, }; $newDoc->fromHash($h); # Or new XML can also be created by manipulating #elements directly: my $newDocRoot = $newDoc->getRoot(); # create the <? xml ?> header my $xmlHeader = $newDocRoot->header('xml'); # add the version $xmlHeader->attribute('version', '1.0'); my $person = $newDocRoot->createChild('person'); my $name = $person->createChild('name'); $name->createChild('first')->text('John'); $name->createChild('last')->text('Doe'); my $eyes = $person->createChild('eyes'); $eyes->attribute('color', 'blue'); $eyes->attribute('number', 2); # output the document print $newDoc->toString(); This example would output : <?xml version="1.0"?> <person> <name> <first> John </first> <last> Doe </last> </name> <eyes color="blue" number="2" /> </person> DESCRIPTION
The XML::Mini::Document class is the programmer's handle to XML::Mini functionality. A XML::Mini::Document instance is created in every program that uses XML::Mini. With the XML::Mini::Document object, you can access the root XML::Mini::Element, find/fetch/create elements and read in or output XML strings. new [XMLSTRING] Creates a new instance of XML::Mini::Document, optionally calling fromString with the passed XMLSTRING getRoot Returns a reference the this document's root element (an instance of XML::Mini::Element) setRoot NEWROOT setRoot NEWROOT Set the document root to the NEWROOT XML::Mini::Element object. isElement ELEMENT Returns a true value if ELEMENT is an instance of XML::Mini::Element, false otherwise. isNode NODE Returns a true value if NODE is an instance of XML::MiniNode, false otherwise. createElement NAME [VALUE] Creates a new XML::Mini::Element with name NAME. This element is an orphan (has no assigned parent) and will be lost unless it is appended (XML::Mini::Element::appendChild()) to an element at some point. If the optional VALUE (string or numeric) parameter is passed, the new element's text/numeric content will be set using VALUE. Returns a reference to the newly created element. getElement NAME [POSITON] Searches the document for an element with name NAME. Returns a reference to the first XML::Mini::Element with name NAME, if found, NULL otherwise. NOTE: The search is performed like this, returning the first element that matches: - Check the Root Element's immediate children (in order) for a match. - Ask each immediate child (in order) to XML::Mini::Element::getElement() (each child will then proceed similarly, checking all it's immediate children in order and then asking them to getElement()) If a numeric POSITION parameter is passed, getElement() will return only the POSITIONth element of name NAME (starting at 1). Thus, on document <?xml version="1.0"?> <people> <person> bob </person> <person> jane </person> <person> ralph </person> </people> $people->getElement('person') will return the element containing the text node 'bob', while $people->getElement('person', 3) will return the element containing the text 'ralph'. getElementByPath PATH [POSITIONARRAY] Attempts to return a reference to the (first) element at PATH where PATH is the path in the structure from the root element to the requested element. For example, in the document represented by: <partRateRequest> <vendor> <accessid user="myusername" password="mypassword" /> </vendor> <partList> <partNum> DA42 </partNum> <partNum> D99983FFF </partNum> <partNum> ss-839uent </partNum> </partList> </partRateRequest> $accessid = $xmlDocument->getElementByPath('partRateRequest/vendor/accessid'); Will return what you expect (the accessid element with attributes user = "myusername" and password = "mypassword"). BUT be careful: my $accessid = $xmlDocument->getElementByPath('partRateRequest/partList/partNum'); will return the partNum element with the value "DA42". To access other partNum elements you must either use the POSITIONSARRAY or the getAllChildren() method on the partRateRequest element. POSITIONSARRAY functions like the POSITION parameter to getElement(), but instead of specifying the position of a single element, you must indicate the position of all elements in the path. Therefore, to get the third part number element, you would use my $thirdPart = $xmlDocument->getElementByPath('partRateRequest/partList/partNum', 1, 1, 3); The additional 1,1,3 parameters indicate that you wish to retrieve the 1st partRateRequest element in the document, the 1st partList child of partRateRequest and the 3rd partNum child of the partList element (in this instance, the partNum element that contains 'ss-839uent'). Returns the XML::Mini::Element reference if found, NULL otherwise. parse SOURCE Initialise the XML::Mini::Document (and its root XML::Mini::Element) using the XML from file SOURCE. SOURCE may be a string containing your XML document. In addition to parsing strings, possible SOURCEs are: # a file location string $miniXMLDoc->parse('/path/to/file.xml'); # an open file handle open(INFILE, '/path/to/file.xml'); $miniXMLDoc->parse(*INFILE); # an open FileHandle object my $fhObj = FileHandle->new(); $fhObj->open('/path/to/file.xml'); $miniXML->parse($fhObj); In all cases where SOURCE is a file or file handle, XML::Mini takes care of slurping the contents and closing the handle. fromHash HASHREF [OPTIONS] Parses a "hash representation" of your XML structure. For each key => value pair within the hash ref, XML::Mini will create an element of name 'key' : - with the text contents set to 'value' if 'value' is a string - for each element of 'value' if value is an ARRAY REFERENCE - with suitable children for each subkey => subvalue if 'value' is a HASH REFERENCE. For instance, if fromHash() is passed a simple hash ref like: my $h = { 'spy' => { 'id' => '007', 'type' => 'SuperSpy', 'name' => 'James Bond', 'email' => 'mi5@london.uk', 'address' => 'Wherever he is needed most', }, }; then : $xmlDoc->fromHash($h); print $xmlDoc->toString(); will output <spy> <email> mi5@london.uk </email> <name> James Bond </name> <address> Wherever he is needed most </address> <type> SuperSpy </type> <id> 007 </id> </spy> The optional OPTIONS parameter may be used to specify which keys to use as attributes (instead of creating subelements). For example, calling my $options = { 'attributes' => { 'spy' => 'id', 'email' => 'type', 'friend' => ['name', 'age'], } }; my $h = { 'spy' => { 'id' => '007', 'type' => 'SuperSpy', 'name' => 'James Bond', 'email' => { 'type' => 'private', '-content' => 'mi5@london.uk', }, 'address' => { 'type' => 'residential', '-content' => 'Wherever he is needed most', }, 'friend' => [ { 'name' => 'claudia', 'age' => 25, 'type' => 'close', }, { 'name' => 'monneypenny', 'age' => '40something', 'type' => 'tease', }, { 'name' => 'Q', 'age' => '10E4', 'type' => 'pain', } ], }, }; $xmlDoc->fromHash($h, $options); print $xmlDoc->toString(); will output something like: <spy id="007"> <name> James Bond </name> <email type="private"> mi5@london.uk </email> <address> <type> residential </type> Wherever he is needed most </address> <type> SuperSpy </type> <friend age="25" name="claudia"> <type> close </type> </friend> <friend age="40something" name="monneypenny"> <type> tease </type> </friend> <friend age="10E4" name="Q"> <type> pain </type> </friend> </spy> As demonstrated above, you can use the optional href to specify tags for which attributes (instead of elements) should be created and you may nest hash and array refs to create complex structures. NOTE: Whenever a hash references is used you lose the sequence in which the elements are placed - only the array references (which create a list of identically named elements) can preserve their order. See ALSO: the documentation for the related toHash() method. Still TODO: Create some better docs for this! For the moment you can take a peek within the test suite of the source distribution. fromString XMLSTRING Initialise the XML::Mini::Document (and it's root XML::Mini::Element) using the XML string XMLSTRING. Returns the number of immediate children the root XML::Mini::Element now has. fromFile FILENAME Initialise the XML::Mini::Document (and it's root XML::Mini::Element) using the XML from file FILNAME. Returns the number of immediate children the root XML::Mini::Element now has. toString [DEPTH] Converts this XML::Mini::Document object to a string and returns it. The optional DEPTH may be passed to set the space offset for the first element. If the optional DEPTH is set to $XML::Mini::NoWhiteSpaces no or whitespaces will be inserted in the xml string (ie it will all be on a single line with no spaces between the tags. Returns a string of XML representing the document. toFile FILENAME [SAFE] Stringify and save the XML document to file FILENAME If SAFE flag is passed and is a true value, toFile will do some extra checking, refusing to open the file if the filename matches m|/../| or m|#;`*| or if FILENAME points to a softlink. In addition, if SAFE is 'NOOVERWRITE', toFile will fail if the FILENAME already exists. toHash Transform the XML structure internally represented within the object (created manually or parsed from a file or string) into a HASH reference and returns the href. For instance, if this XML is parse()d: <people> <person id="007"> <email> mi5@london.uk </email> <name> James Bond </name> <address> Wherever he is needed most </address> <type> SuperSpy </type> </person> <person id="006" number="6"> <comment> I am not a man, I am a free number </comment> <name> Number 6 </name> <email type="private"> prisoner@aol.com </email> <address> 6 Prison Island Road, Prison Island, Somewhere </address> </person> </people> The hash reference returned will look like this (as output by Data::Dumper): 'people' => { 'person' => [ { 'email' => 'mi5@london.uk', 'name' => 'James Bond', 'type' => 'SuperSpy', 'address' => 'Wherever he is needed most', 'id' => '007' }, { 'email' => { 'type' => 'private', '-content' => 'prisoner@aol.com' }, 'comment' => 'I am not a man, I am a free number', 'number' => '6', 'name' => 'Number 6', 'address' => '6 Prison Island Road, Prison Island, Somewhere', 'id' => '006' } ] } getValue Utility function, call the root XML::Mini::Element's getValue() dump Debugging aid, dump returns a nicely formatted dump of the current structure of the XML::Mini::Document object. CAVEATS
It is impossible to parse "cross-nested" tags using regular expressions (i.e. sequences of the form <a><b><a>...</a></b></a>). However, if you have the Text::Balanced module installed (it is installed by default with Perl 5.8), such sequences will be handled flawlessly. Even if you do not have the Text::Balanced module available, it is still possible to generate this type of XML - the problem only appears when parsing. AUTHOR
Copyright (C) 2002-2008 Patrick Deegan, Psychogenic Inc. Programs that use this code are bound to the terms and conditions of the GNU GPL (see the LICENSE file). If you wish to include these modules in non-GPL code, you need prior written authorisation from the authors. This library is released under the terms of the GNU GPL version 3, making it available only for free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details). Anyone wishing to use this library within a proprietary or otherwise non- GPLed program MUST contact psychogenic.com to acquire a distinct license for their application. This approach encourages the use of free software while allowing for proprietary solutions that support further development. LICENSE XML::Mini::Document module, part of the XML::Mini XML parser/generator package. Copyright (C) 2002-2008 Patrick Deegan All rights reserved XML::Mini is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. XML::Mini is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with XML::Mini. If not, see <http://www.gnu.org/licenses/>. SEE ALSO
XML::Mini, XML::Mini::Element http://minixml.psychogenic.com perl v5.10.0 2009-09-20 XML::Mini::Document(3pm)
All times are GMT -4. The time now is 08:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy