Sponsored Content
Top Forums Shell Programming and Scripting searching multiple lines and replacing in shell scripting Post 302523645 by birei on Thursday 19th of May 2011 09:20:09 AM
Old 05-19-2011
Hi,

I'm not sure I understood your problem correctly. Test next 'Perl' script. Perhaps it works:

Code:
$ cat script.pl
use strict;
use warnings;
use autodie;

@ARGV == 1 or die "Usage: perl $0 infile\n";
open my $fh, "<", $ARGV[0];
my ($flag, $line);

while ( <$fh> ) {
    if ( /^(?i:ssenthil)/ ) {
        $flag = 1;
        next;
    } else {
        print $line if defined $line && ! $flag;
    }  
    if ( $flag ) {
        $flag = 0;
        unless ( /^\[.*\]$/ || /^\s*$/ ) {
            print $line;
        }  
    }  
    $line = $_;
}

print $line;
$ perl script.pl infile
(Output supressed)

Regards,
Birei
This User Gave Thanks to birei For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing multiple lines

i have a file : sample1.txt OBJECT="POINT" ACTION="REDEFINE" POINT_NAME="ABCD001G " GHYT_POPRIORITY_1="1" GHYT_POPRIORITY_2="1" GHYT_POPRIORITY_3="1" GHYT_POPRIORITY_4="1" GHYT_POPRIORITY_USER="1" HIGH_ALARM_PRIORITY_1="1" HIGH_ALARM_PRIORITY_2="1" HIGH_ALARM_PRIORITY_3="1" ... (1 Reply)
Discussion started by: ajnabi
1 Replies

2. Shell Programming and Scripting

replacing multiple lines with single line

Can any one give me the idea on replacing multiple blank lines with a single blank line? Please conside it for a file having more than 100 number of characters. Regards, Siba (3 Replies)
Discussion started by: siba.s.nayak
3 Replies

3. Shell Programming and Scripting

searching thru or combining multiple lines in a unix file

This is the problem actually: This regex: egrep "low debug.*\".*\"" $dbDir/alarmNotification.log is looking for data between the two quotation marks: ".*\" When I hate data like this: low debug 2009/3/9 8:30:20.47 ICSNotificationAlarm Prodics01ics0003 IC... (0 Replies)
Discussion started by: ndedhia1
0 Replies

4. Shell Programming and Scripting

Replacing pattern spanning multiple lines

Hi. I have input like this: <tr> <td class="logo1" rowspan="2"><a href="index.html"><img src="images/logo.png" /></a></td> <td class="pad1" rowspan="2">__</td> <td class="userBox"><img src="images/person.png"/> <a href="http://good.mybook.com/login.jsp">Sign In</a></td> <td... (5 Replies)
Discussion started by: zorrox
5 Replies

5. Shell Programming and Scripting

Nawk help searching for multiple lines and multiple searches

I use this command to find a search (Nr of active alarms are) and print one line before and 10 lines after the search keywords. nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=1 a=10 s="Nr of active alarms are:" *.log However, I would like to know how to tell it to print... (3 Replies)
Discussion started by: tthach830
3 Replies

6. Shell Programming and Scripting

Bash Scripting Help to automate replacing multiple lines

Background: I am writing a script to help me automate tweaks and things I apply to a custom Android rom I developed. I am on the very last part of my script, and I am stuck trying to find the right command to do what I seek. When I build roms from source, a file called updater-script is... (8 Replies)
Discussion started by: Silverlink34
8 Replies

7. Shell Programming and Scripting

Replacing a single line with multiple lines in a file

Hi Am confused with the usage of "sed" command I want to replace a single line with multiple lines of a file.. eg., A file has Hi, How are you? I need to replace as Am fine What are You doing? I used the script as string1="Hi, How are you?" echo "$string1 is the value"... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

8. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

9. Shell Programming and Scripting

Need help in replacing a variable in shell scripting

Experts, Can someone help me with the below? I've a variable called NSPMHOME=some_value. I would like change the value of the variable with another variable and something followed by it. E.g From NSPHOME=some_value to NSPMHOME=$SOMETHING/test $SOMETHING has value /opt/tag . The end... (4 Replies)
Discussion started by: jawaugh
4 Replies

10. UNIX for Beginners Questions & Answers

Export Oracle multiple tables to multiple csv files using UNIX shell scripting

Hello All, just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table. Can you please suggest why? or any better idea? export FILE="/abc/autom/file/geo_JOB.csv" Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Discussion started by: Hope
16 Replies
Test::Strict(3pm)					User Contributed Perl Documentation					 Test::Strict(3pm)

NAME
Test::Strict - Check syntax, presence of use strict; and test coverage SYNOPSIS
"Test::Strict" lets you check the syntax, presence of "use strict;" and presence "use warnings;" in your perl code. It report its results in standard "Test::Simple" fashion: use Test::Strict tests => 3; syntax_ok( 'bin/myscript.pl' ); strict_ok( 'My::Module', "use strict; in My::Module" ); warnings_ok( 'lib/My/Module.pm' ); Module authors can include the following in a t/strict.t and have "Test::Strict" automatically find and check all perl files in a module distribution: use Test::Strict; all_perl_files_ok(); # Syntax ok and use strict; or use Test::Strict; all_perl_files_ok( @mydirs ); "Test::Strict" can also enforce a minimum test coverage the test suite should reach. Module authors can include the following in a t/cover.t and have "Test::Strict" automatically check the test coverage: use Test::Strict; all_cover_ok( 80 ); # at least 80% coverage or use Test::Strict; all_cover_ok( 80, 't/' ); DESCRIPTION
The most basic test one can write is "does it compile ?". This module tests if the code compiles and play nice with "Test::Simple" modules. Another good practice this module can test is to "use strict;" in all perl files. By setting a minimum test coverage through "all_cover_ok()", a code author can ensure his code is tested above a preset level of kwality throughout the development cycle. Along with Test::Pod, this module can provide the first tests to setup for a module author. This module should be able to run under the -T flag for perl >= 5.6. All paths are untainted with the following pattern: "qr|^([-+@w./:\]+)$|" controlled by $Test::Strict::UNTAINT_PATTERN. FUNCTIONS
syntax_ok( $file [, $text] ) Run a syntax check on $file by running "perl -c $file" with an external perl interpreter. The external perl interpreter path is stored in $Test::Strict::PERL which can be modified. You may prefer "use_ok()" from Test::More to syntax test a module. For a module, the path (lib/My/Module.pm) or the name (My::Module) can be both used. strict_ok( $file [, $text] ) Check if $file contains a "use strict;" statement. "use Moose" and "use Mouse" are also considered valid. This is a pretty naive test which may be fooled in some edge cases. For a module, the path (lib/My/Module.pm) or the name (My::Module) can be both used. warnings_ok( $file [, $text] ) Check if warnings have been turned on. If $file is a module, check if it contains a "use warnings;" or "use warnings::..." or "use Moose" or "use Mouse" statement. If the perl version is <= 5.6, this test is skipped ("use warnings" appeared in perl 5.6). If $file is a script, check if it starts with "#!...perl -w". If the -w is not found and perl is >= 5.6, check for a "use warnings;" or "use warnings::..." or "use Moose" or "use Mouse" statement. This is a pretty naive test which may be fooled in some edge cases. For a module, the path (lib/My/Module.pm) or the name (My::Module) can be both used. all_perl_files_ok( [ @directories ] ) Applies "strict_ok()" and "syntax_ok()" to all perl files found in @directories (and sub directories). If no <@directories> is given, the starting point is one level above the current running script, that should cover all the files of a typical CPAN distribution. A perl file is *.pl or *.pm or *.t or a file starting with "#!...perl" If the test plan is defined: use Test::Strict tests => 18; all_perl_files_ok(); the total number of files tested must be specified. You can control which tests are run on each perl site through: $Test::Strict::TEST_SYNTAX (default = 1) $Test::Strict::TEST_STRICT (default = 1) $Test::Strict::TEST_WARNINGS (default = 0) $Test::Strict::TEST_SKIP (default = []) "Trusted" files to skip all_cover_ok( [coverage_threshold [, @t_dirs]] ) This will run all the tests in @t_dirs (or current script's directory if @t_dirs is undef) under Devel::Cover and calculate the global test coverage of the code loaded by the tests. If the test coverage is greater or equal than "coverage_threshold", it is a pass, otherwise it's a fail. The default coverage threshold is 50 (meaning 50% of the code loaded has been covered by test). The threshold can be modified through $Test::Strict::COVERAGE_THRESHOLD. You may want to select which files are selected for code coverage through $Test::Strict::DEVEL_COVER_OPTIONS, see Devel::Cover for the list of available options. The default is '+ignore,"/Test/Strict"'. The path to "cover" utility can be modified through $Test::Strict::COVER. The 50% threshold is a completely arbitrary value, which should not be considered as a good enough coverage. The total coverage is the return value of "all_cover_ok()". CAVEATS
For "all_cover_ok()" to work properly, it is strongly advised to install the most recent version of Devel::Cover and use perl 5.8.1 or above. In the case of a "make test" scenario, "all_perl_files_ok()" re-run all the tests in a separate perl interpreter, this may lead to some side effects. SEE ALSO
Test::More, Test::Pod. Test::Distribution, <Test:NoWarnings> AUTHOR
Pierre Denis, "<pdenis@gmail.com>". COPYRIGHT
Copyright 2005, 2010 Pierre Denis, All Rights Reserved. You may use, modify, and distribute this package under the same terms as Perl itself. perl v5.10.1 2010-02-14 Test::Strict(3pm)
All times are GMT -4. The time now is 08:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy