Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Replace a patern_2 in 30 lines from the line with the patern_1 founded

by thao4 (Initiate)
on Feb 21, 2018 at 10:05 UTC ( [id://1209644]=perlquestion: print w/replies, xml ) Need Help??

thao4 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am new in perl. I need do somthing in perl: exemple: - search a patern "CADRE 1.1 CPU" in one file.txt - incremente +30 lines from the line with the patern found - replace the new patern "Model Regle" by "Heath Rule A" in this new line (30 lines after the line with patern "CADRE 1.1 CPU" Could you help me, please, thank you very much exemple of the text

  • Comment on Replace a patern_2 in 30 lines from the line with the patern_1 founded

Replies are listed 'Best First'.
Re: Replace a patern_2 in 30 lines from the line with the patern_1 founded
by thanos1983 (Parson) on Feb 21, 2018 at 10:29 UTC

    Hello thao4,

    Welcome to the Monastery. I would not recommend us to do your work. We are here to help you not to complete the assignment for you. If you are not good in Perl start reading and writing code. Post your questions here when you can not find an answer and we will be more than happy to guide you.

    Today you have this problem / task that you are trying to resolve tomorrow? Having said that a good starting point for you could be Read strings from a file, search and replace same string in another file.

    Start writing some code and if you get stack and you can not find the solution online post a question with sample of your code and data and we will assist you as much as possible.

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re: Replace a patern_2 in 30 lines from the line with the patern_1 founded
by karlgoethebier (Abbot) on Feb 21, 2018 at 16:30 UTC

    Just some ideas:

    #!/usr/bin/env perl use strict; use warnings; use Data::Dump; sub indexes(&@); my @array = <DATA>; chomp @array; dd \@array; my @idxs = indexes { $_ eq "bar" } @array; dd \@idxs; sub indexes(&@) { my $test = shift; grep { local *_ = \$_[$_]; $test->() } 0 .. $#_; } __DATA__ foo bar nose cuke foo bar nose cuke

    I cheated a little bit from List::MoreUtils.

    This stuff isn't so easy - but we grow with our tasks ;-)

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1209644]
Approved by Eily
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found