Sponsored Content
Top Forums Shell Programming and Scripting Select block of text around matching braces Post 302295944 by BootComp on Tuesday 10th of March 2009 03:29:49 AM
Old 03-10-2009
Quote:
Originally Posted by summer_cherry
Code:
#!/usr/bin/perl
undef $/;
open FH,"<a.txt";
$str=<FH>;
@arr=split(/#[0-9]+.* Block/,$str);
map {s/[\n ]//g} @arr;
print join "\n",@arr;

Thanks. But would be great if I could explanation of the above code for my understanding.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Select last block from a file

Hi, I have to always select last portion of a block identified by 2 fixed keywords which repeats in a file for eg START .... ... END START .... ... END START .... ... END (9 Replies)
Discussion started by: misenkiser
9 Replies

2. UNIX for Dummies Questions & Answers

Select text within matching ( ) bracket

Hi, I am looking for a simple command to select text within a open bracket "(" and a matching close bracket ")" and output the within-bracket-text to a file. This function is similar to the common vi select a range of text with "(" to ")" but not sure how to run the same function in command... (4 Replies)
Discussion started by: cursive
4 Replies

3. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: Rajendra_1510
3 Replies

4. 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

5. UNIX for Dummies Questions & Answers

How to select text within the second ()?

Hello, Can someone advise me how to select the text within the second bracket of a string in shell script? For example, the input file: some message (string A) some message (string B) some message (string C) some message (string D) some message (string E) The number of bracket is random... (4 Replies)
Discussion started by: hanul
4 Replies

6. Shell Programming and Scripting

Block of records to select from a file

Hello: I am new to shell script programming. Now I would like to select specific records block from a file. For example, current file "xyz.txt" is containing 1million records and want to select the block of records from line number 50000 to 100000 and save into a file. Can anyone suggest me how... (3 Replies)
Discussion started by: nvkuriseti
3 Replies

7. Shell Programming and Scripting

Select the exact matching contents using grep

Hi everyone I've two files.. The contents of file1 are as shown below 4 5 12 13 36 37 45 46 47 The contents of file2 are as shown below 21 hello 13 world (5 Replies)
Discussion started by: abk07
5 Replies

8. Shell Programming and Scripting

Like to select text in a From/To list

Hi I need help to configure AWK to find a string based From/To filed I have a table like this 0A00 - 0AFF Nuts 0B00 - 0BFF Bolt If I have in a program a value like "0B22" I wold like to get "Bolt" in return. List are in Hex Still try to learn AWK :) (3 Replies)
Discussion started by: Jotne
3 Replies

9. Shell Programming and Scripting

Grep text matching problem with script which checks if web page contains text.

I wrote a Bash script which checks to see if a text string exists on a web page and then sends me an email if it does (or does not e.g. "Out of stock"). I run it from my crontab, it's quite handy from time to time and I've been using it for a few years now. The script uses wget to download an... (6 Replies)
Discussion started by: gencon
6 Replies

10. Shell Programming and Scripting

How do I select certain columns with matching pattern and rest of the lines?

I want to select 2nd, 3rd columns if line has "key3" and print rest of the lines as is. # This is my sample input key1="val1" key2="val2" key3="val3" key4="val4" some text some text some text some text key1="val1" key2="val2" key3="val3" key4="val4" some text some text some text some... (3 Replies)
Discussion started by: kchinnam
3 Replies
MakeMethods::Utility::TextBuilder(3pm)			User Contributed Perl Documentation		    MakeMethods::Utility::TextBuilder(3pm)

NAME
Class::MakeMethods::Utility::TextBuilder - Basic text substitutions SYNOPSIS
print text_builder( $base_text, @exprs ) DESCRIPTION
This module provides a single function, which implements a simple "text macro" mechanism for assembling templated text strings. $expanded_text = text_builder( $base_text, @exprs ) Returns a modified copy of $base_text using rules from the @exprs list. The @exprs list may contain any of the following: o A string, in which any '*' characters will be replaced by the base text. The interpolated string then replaces the base text. o A code-ref, which will be called with the base text as its only argument. The result of that call then replaces the base text. o A hash-ref, which will be added to the substitution hash used in the second pass, below. o An array-ref, containing additional expressions to be treated as above. After any initial string and code-ref rules have been applied, the hash of substitution rules are applied. The text will be searched for occurances of the keys of the substitution hash, which will be modified based on the corresponding value in the hash. If the substitution key ends with '{}', the search will also match a balanced block of braces, and that value will also be used in the substitution. The hash-ref may contain the following types of rules: o 'string' => 'string' Occurances of the first string are to be replaced by the second. o 'string' => code_ref Occurances of the string are to be replaced by the results of calling the subroutine with no arguments. o 'string{}' => 'string' Occurances of the first string and subsequent block of braces are replaced by a copy of the second string in which any '*' characters have first been replaced by the contents of the brace block. o 'string{}' => code_ref Occurances of the string and subsequent block of braces are replaced by the results of calling the subroutine with the contents of the brace block as its only argument. o 'string{}' => hash_ref Occurances of the string and subsequent block of braces are replaced by using the contents of the brace block as a key into the provided hash-ref. EXAMPLE
The following text and modification rules provides a skeleton for a collection letter: my $letter = "You owe us AMOUNT. Please pay up! " . "THREAT{SEVERITY}"; my @exprs = ( "Dear NAMEm *", "* -- The Management", { 'THREAT{}' => { 'good'=>'Please?', 'bad'=>'Or else!' } }, " DATE *", { 'DATE' => 'Tuesday, April 1, 2001' }, ); One might invoke this template by providing additional data for a given instance and calling the text_builder function: my $item = { 'NAME'=>'John', 'AMOUNT'=>'200 camels', 'SEVERITY'=>'bad' }; print text_builder( $letter, @exprs, $item ); The resulting output is shown below: Tuesday, April 1, 2001 Dear John, You owe us 200 camels. Please pay up! Or else! -- The Management SEE ALSO
See Class::MakeMethods for general information about this distribution. perl v5.10.1 2004-09-06 MakeMethods::Utility::TextBuilder(3pm)
All times are GMT -4. The time now is 09:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy