Sponsored Content
Top Forums Shell Programming and Scripting Capture string contained on a line? Post 302827331 by Corona688 on Friday 28th of June 2013 12:18:35 PM
Old 06-28-2013
That's exactly what it's doing, yes. For every 'line', check if FCH is in it, and if so, print.

Given this text:

Code:
<html><body><h1>HI!</h1></body></html>

it will interpret it like this:

Code:
html
body
h1      HI!
/h1
/body
/html

Not a bad way to make a rough-cut XML/HTML/whatever parser, though far from compliant, and some awks have an annoying 2000-byte "line" size limit.

Last edited by Corona688; 06-28-2013 at 01:30 PM..
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a string under a directory that is contained in another file

Hi I am loking for some help in writing a script that will take a number that is located in one file and search a folder structure for that string in any file under that directory. I can do this manually with : find /"directory" -type f -exec grep -l 'Number String' {} \; But now I will... (3 Replies)
Discussion started by: BMC
3 Replies

2. UNIX for Dummies Questions & Answers

Modifying a particulae data in a line contained in File

Hi, I have a file containing data: systemname/userid/password/comment systemname1/userid1/password1/comment1 systemname2/userid2/password2/comment2 I want to modify the "password" using script. Can anybody help me with this problem?:confused: (2 Replies)
Discussion started by: pgarg1989
2 Replies

3. Shell Programming and Scripting

Need to capture certain text from a string in a different file

Hi, I wanted to know how i could accomplish this in a script using ksh. Lets say there is a file called test.dat and it has a certain input like below : . . Hi = 56 Hi = 67 . . 1 record(s) selected Now i need to capture the numbers after the = sign and store them in a... (3 Replies)
Discussion started by: Siddarth
3 Replies

4. UNIX for Advanced & Expert Users

capture data from matched string/line

Hi, I have a query as follows : suppose I am matching a string in a file say "start from here" and I want to pick up 'n' number of lines () from the matched string. Is there any way to do that ? 1) going forward I want to do this for every match for the above string 2) or limit this to... (2 Replies)
Discussion started by: sumoka
2 Replies

5. Shell Programming and Scripting

How to capture a string enclose by a pattern within a file?

Hi all, My file :test.txt just like this: ........................... From: 333:123<sip:88888888888@bbbb.com To: <sip:123456@aaaaa.com ......................... I want a script to capture the string between sip: & @ Expect output: 88888888888 123456 Please help! (4 Replies)
Discussion started by: Alex Li
4 Replies

6. Shell Programming and Scripting

awk help string capture

Dear All My input file as under. From it I want op fine as mention below. Kindly help. I use below code but not help. code: awk -F" " '{print $2}' ip file: "BSCJNGR_IPA17_C" 030 131207 1305 RXOCF-353 PBD011_BGIL BOTH AC FAULTY "BSCJNGR_IPA17_C" 991 131207 1637 RXOCF-224 NAV001_BGIL ... (5 Replies)
Discussion started by: jaydeep_sadaria
5 Replies

7. Shell Programming and Scripting

String capture from ip file

Dear All From below mention input file I want op file as mention. Kindly help. IP file: "BSCGNR4_IPA17_C" 329 140119 0717 RXOCF-105 KJO001_BASC_NG AC FAULTY DG ON DOOR OPEN Needed OP: 140119 0717 KJO001_BASC_NG AC FAULTY DG ON DOOR OPEN Note that string mark in red as variable in... (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies

8. Shell Programming and Scripting

How to capture string below a line?

Hi, I need to collect IP address of all servers (more than 300). One way is put it in for loop and run nslookup for that servers list, but there are multiple fields in output. (tty/dev/pts/13): bash: 1011 > nslookup vplssor04 Server: 10.58.115.34 Address: 10.58.115.34#53 Name: ... (7 Replies)
Discussion started by: solaris_1977
7 Replies

9. Shell Programming and Scripting

Script to capture string in a log file

Dear all, I have a log file to be analysed. this log file contains vaiours lines of code starting with date timestamp. if my search string is exception then that resepective log statement starting from the date is required. example: 2014/10/01 16:14:44.459|>=|E|X|19202496|2832|... (5 Replies)
Discussion started by: shravee
5 Replies

10. Shell Programming and Scripting

Awk:String search more than one time and capture OP

Dear All During one of mine script developemnt i am stuch at one sub part. Requiremnt is as below kindly help me. IP file: 2015-02-28 10:10:15 AL M UtranCell UtranCell=RTE001X (unavailable) 2015-02-28 10:10:15 AL M UtranCell UtranCell=RTE001Y (unavailable) 2015-02-28 10:10:15 AL M... (6 Replies)
Discussion started by: jaydeep_sadaria
6 Replies
HTML::TreeBuilder::XPath(3pm)				User Contributed Perl Documentation			     HTML::TreeBuilder::XPath(3pm)

NAME
HTML::TreeBuilder::XPath - add XPath support to HTML::TreeBuilder SYNOPSIS
use HTML::TreeBuilder::XPath; my $tree= HTML::TreeBuilder::XPath->new; $tree->parse_file( "mypage.html"); my $nb=$tree->findvalue( '/html/body//p[@class="section_title"]/span[@class="nb"]'); my $id=$tree->findvalue( '/html/body//p[@class="section_title"]/@id'); my $p= $html->findnodes( '//p[@id="toto"]')->[0]; my $link_texts= $p->findvalue( './a'); # the texts of all a elements in $p $tree->delete; # to avoid memory leaks, if you parse many HTML documents DESCRIPTION
This module adds typical XPath methods to HTML::TreeBuilder, to make it easy to query a document. METHODS
Extra methods added both to the tree object and to each element: findnodes ($path) Returns a list of nodes found by $path. In scalar context returns an "Tree::XPathEngine::NodeSet" object. findnodes_as_string ($path) Returns the text values of the nodes, as one string. findnodes_as_strings ($path) Returns a list of the values of the result nodes. findvalue ($path) Returns either a "Tree::XPathEngine::Literal", a "Tree::XPathEngine::Boolean" or a "Tree::XPathEngine::Number" object. If the path returns a NodeSet, $nodeset->xpath_to_literal is called automatically for you (and thus a "Tree::XPathEngine::Literal" is returned). Note that for each of the objects stringification is overloaded, so you can just print the value found, or manipulate it in the ways you would a normal perl value (e.g. using regular expressions). findvalues ($path) Returns the values of the matching nodes as a list. This is mostly the same as findnodes_as_strings, except that the elements of the list are objects (with overloaded stringification) instead of plain strings. exists ($path) Returns true if the given path exists. matches($path) Returns true if the element matches the path. find ($path) The find function takes an XPath expression (a string) and returns either a Tree::XPathEngine::NodeSet object containing the nodes it found (or empty if no nodes matched the path), or one of XML::XPathEngine::Literal (a string), XML::XPathEngine::Number, or XML::XPathEngine::Boolean. It should always return something - and you can use ->isa() to find out what it returned. If you need to check how many nodes it found you should check $nodeset->size. See XML::XPathEngine::NodeSet. as_XML_compact HTML::TreeBuilder's "as_XML" output is not really nice to look at, so I added a new method, that can be used as a simple replacement for it. It escapes only the '<', '>' and '&' (plus '"' in attribute values), and wraps CDATA elements in CDATA sections. Note that the XML is actually not garanteed to be valid at this point. Nothing is done about the encoding of the string. Patches or just ideas of how it could work are welcome. as_XML_indented Same as as_XML, except that the output is indented. SEE ALSO
HTML::TreeBuilder XML::XPathEngine REPOSITORY
https://github.com/mirod/HTML--TreeBuilder--XPath <https://github.com/mirod/HTML--TreeBuilder--XPath> AUTHOR
Michel Rodriguez, <mirod@cpan.org> COPYRIGHT AND LICENSE
Copyright (C) 2006-2011 by Michel Rodriguez This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available. perl v5.12.4 2011-09-20 HTML::TreeBuilder::XPath(3pm)
All times are GMT -4. The time now is 01:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy