Sponsored Content
Top Forums Shell Programming and Scripting Finding the line number of matching braces Post 302243342 by Rajendra_1510 on Sunday 5th of October 2008 01:17:51 AM
Old 10-05-2008
Finding the line number of matching braces

Hi,I am new to shell scripting and i want to find the line numbers of matching braces.

The file contents are as follows

File XXX.dat

1 ( CLASS "FRUIT"
2 (TYPE "PERSISTENT")
3 (MESSAGE_TYPE "M")
4 (GET_REQRD "Y")
5 (SET_REQRD "Y")
6 )
7 ( CLASS "VEGETABLES"
8 (TYPE "PERSISTENT")
9 (MESSAGE_TYPE "N")
10 (GET_REQRD "N")
11 )
12 ( CLASS "SEED"
13 (TYPE "PERSISTENT")
14 (MESSAGE_TYPE "N")
15 (SET_REQRD "N")
16 )


Now I want to get the line numbers 7and 11 that matches braces of class
"VAGETABLES". 7 is the line number of starting brace of class "VEGETABLES" and 11 is the line number of ending brace of CLASS "VEGETABLES".I want the starting and ending line number to be stored in two different variables,say START_LINE_NUMBER and END_LINE_NUMBER.
Can you please help me? Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to find matching braces using sed or in shell script

hi, I want to print all the lines between the matching braces. For example,the file contains like the below. asdfsdf fsdfsd WO{ w1{ ada ... (3 Replies)
Discussion started by: Boopesh
3 Replies

2. Shell Programming and Scripting

finding the line number from a grep ?

Hi there does anybody know how i can get the line number from an entry or entries in a file ?? for example if i had a file test1 test2 test3 test1 and i needed to get the line numbers for all instances of test1 in that file with the answer being (1,4) Would anybody be able... (7 Replies)
Discussion started by: hcclnoodles
7 Replies

3. Shell Programming and Scripting

Finding opening and closing braces

I am reading a cpp file thru shell script . There are many fuctions inside the cpp file eg pvvd_fncn_name1 { ..... something } pvvd_fncn_name2 { ..... something } what I require is a method to find the first opening brace and the coresponding last brace and search... (2 Replies)
Discussion started by: ultimatix
2 Replies

4. Shell Programming and Scripting

Select block of text around matching braces

Hi, I have several block of text that I need to select, however this text may be spread over several lines and contains the '{' and '}' within it. For e.g., ABC=100{ DEF = 200 { GHI, JKL } } #2nd Block 123 { 456{78,910}} }I am trying to figure out how to remove... (2 Replies)
Discussion started by: BootComp
2 Replies

5. Shell Programming and Scripting

finding the number of occurence of a word in a line

suppose i have this line abs|der|gt|dftnrk|dtre i want to count the number of "|" in this line.. how can i do that. plz help:confused: (9 Replies)
Discussion started by: priyanka3006
9 Replies

6. Shell Programming and Scripting

Finding line with highest number in a file

Hi All, My file looks some thing like this, File 1: - A 10 B 30 C 5 D 25 E 72 F 23 now my requirement is to find the line with highest number in it, i;e the result should be E 72 Thanks in Advance (1 Reply)
Discussion started by: balu_puttaganti
1 Replies

7. Shell Programming and Scripting

find out line number of matching string using grep

Hi all, I want to display line number for matching string in a file. can anyone please help me. I used grep -n "ABC" file so it displays 6 ABC. But i only want to have line number,i don't want that it should prefix matching context with line number. Actually my original... (10 Replies)
Discussion started by: sarbjit
10 Replies

8. Shell Programming and Scripting

Finding the line with the exact same number

Hello All, What i am doing is , i tail a file from certain chatacter and then cat -n to get the line numbers.I search for a particular string and gets it line number. What i am interested in is the next line immediately after the pattern i search. But grep gives me result for all line... (5 Replies)
Discussion started by: kailash19
5 Replies

9. Shell Programming and Scripting

finding the line number of a particular line in a file

Hi Frnds, I need to find the line number of a particular line in a file and store that line number to a variable. if a file named myfile contains following look at the sun look at the moon look at the star look at the ocean i need to get the line number of the line 'look at the... (3 Replies)
Discussion started by: mvignesh
3 Replies

10. Shell Programming and Scripting

help for fast way of finding line number for a regex

Hello, I am trying to find out the line numbers where regex match and put them into a file with below command: awk '/'$pat'/ {print NR}' $fileName >> temp.txt where $pat is the regex but this command is taking a lot of time to execute with bigger files for size more than 5000000... (8 Replies)
Discussion started by: JoeColeEPL9
8 Replies
PPI::Structure(3)					User Contributed Perl Documentation					 PPI::Structure(3)

NAME
PPI::Structure - The base class for Perl braced structures INHERITANCE
PPI::Structure isa PPI::Node isa PPI::Element DESCRIPTION
PPI::Structure is the root class for all Perl bracing structures. This covers all forms of " [ ... ] ", " { ... } ", and " ( ... ) " brace types, and includes cases where only one half of the pair exist. The class PPI::Structure itself is full abstract and no objects of that type should actually exist in the tree. Elements vs Children A PPI::Structure has an unusual existance. Unlike a PPI::Document or PPI::Statement, which both simply contain other elements, a structure both contains and consists of content. That is, the brace tokens are not considered to be "children" of the structure, but are part of it. In practice, this will mean that while the ->elements and ->tokens methods (and related) will return a list with the brace tokens at either end, the ->children method explicitly will not return the brace. STRUCTURE CLASSES
Excluding the transient PPI::Structure::Unknown that exists briefly inside the parser, there are eight types of structure. PPI::Structure::List This covers all round braces used for function arguments, in "foreach" loops, literal lists, and braces used for precedence-ordering purposes. PPI::Structure::For Although not used for the "foreach" loop list, this is used for the special case of the round-brace three-part semicolon-seperated "for" loop expression (the traditional C style for loop). PPI::Structure::Given This is for the expression being matched in switch statements. PPI::Structure::When This is for the matching expression in "when" statements. PPI::Structure::Condition This round-brace structure covers boolean conditional braces, such as for "if" and "while" blocks. PPI::Structure::Block This curly-brace and common structure is used for all form of code blocks. This includes those for "if", "do" and similar, as well as "grep", "map", "sort", "sub" and (labelled or anonymous) scoping blocks. PPI::Structure::Constructor This class covers brace structures used for the construction of anonymous "ARRAY" and "HASH" references. PPI::Structure::Subscript This class covers square-braces and curly-braces used after a -> pointer to access the subscript of an "ARRAY" or "HASH". METHODS
"PPI::Structure" itself has very few methods. Most of the time, you will be working with the more generic PPI::Element or PPI::Node methods, or one of the methods that are subclass-specific. start For lack of better terminology (like "open" and "close") that has not already in use for some other more important purpose, the two individual braces for the structure are known within PPI as the "start" and "finish" braces (at least for method purposes). The "start" method returns the start brace for the structure (i.e. the opening brace). Returns the brace as a PPI::Token::Structure or "undef" if the structure does not have a starting brace. Under normal parsing circumstances this should never occur, but may happen due to manipulation of the PDOM tree. finish The "finish" method returns the finish brace for the structure (i.e. the closing brace). Returns the brace as a PPI::Token::Structure or "undef" if the structure does not have a finishing brace. This can be quite common if the document is not complete (for example, from an editor where the user may be halfway through typeing a subroutine). braces The "braces" method is a utility method which returns the brace type, regardless of whether has both braces defined, or just the starting brace, or just the ending brace. Returns on of the three strings '[]', '{}', or '()', or "undef" on error (primarily not having a start brace, as mentioned above). complete The "complete" method is a convenience method that returns true if the both braces are defined for the structure, or false if only one brace is defined. Unlike the top level "complete" method which checks for completeness in depth, the structure complete method ONLY confirms completeness for the braces, and does not recurse downwards. SUPPORT
See the support section in the main module. AUTHOR
Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2001 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.16.2 2011-02-25 PPI::Structure(3)
All times are GMT -4. The time now is 08:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy