![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding a columnfrom a specifit line number to a specific line number | Ezy | Shell Programming and Scripting | 2 | 05-12-2008 09:29 AM |
| Appending line number to each line and getting total number of lines | chiru_h | Shell Programming and Scripting | 2 | 03-25-2008 10:19 AM |
| How to grep / zgrep to output ONLY the matching filename and line number? | vvaidyan | UNIX for Dummies Questions & Answers | 3 | 03-12-2008 05:33 PM |
| finding duplicate files by size and finding pattern matching and its count | jerome Sukumar | Shell Programming and Scripting | 2 | 12-01-2006 04:20 AM |
| Need help matching a number | x96riley3 | Shell Programming and Scripting | 1 | 04-04-2006 12:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? ![]() |
|
||||
|
try below perl script Code:
$class=shift;
open (FH,"<filename") or die "Can not open file!";
while(<FH>){
if(m/$class/){
print "Starting ",$.,"\n";
$flag=1;
}
if(m/^\)/ && $flag==1){
print "Ending ",$.,"\n";
$flag=0;
}
}
close(FH);
|
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|