Hi steph_bow,
You can get the previous text from the matching string by using '$`' and the following text by using '$'' like,
#!/usr/bin/perl use strict; use warnings; my $element = "coucou"; open (INFILE, "<EXEMPLE.txt"); while (my $line = <INFILE>){ if ($line =~ /$element/){ my $pre=$`;###to get the previous text from the matching t +ext my $post=$';###to get the following text from the matching + text print "PREVIOUS:$pre\nFOLLOWING:$post\n"; } } close INFILE;
Punitha
In reply to Re: get the rest of the text
by Punitha
in thread get the rest of the text
by steph_bow
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |