giridharreddy9 has asked for the wisdom of the Perl Monks concerning the following question:
What I need to achieve is to print all the words between the substrings "input" and "output" excluding both of them into another file. I have managed to achieve a part of the task. I am able to print from CK i.e after "input" to the end of that line i.e n3070gat. I am not able to print the lines below it.input CK, n3065gat, n3066gat, n3067gat, n3068gat, n3069gat, n3070gat, +n3100gat, test_si, test_se; output n3104gat, n3105gat, n3106gat, n3107gat, n3108gat, n3109gat, n +3110gat;
Please note that I am replacing all the "comma's" with ";" at the same time while writing to the file. Also the substring input always starts at an offset of 7. I would appreciate if anyone could suggest any modifications/additions to the code. --Giridharopen(DATA, "s5378_scan.v") or die "error: $!"; while (<DATA>) { if ($_ =~ /input/) { $length_line = length ($_); $x= $length_line - 7; $portion = substr($_, 7, $x); } my $str = $portion; my $find = ","; my $replace = ";"; $find = quotemeta $find; $str =~ s/$find/$replace/g; open (MYFILE, '>data.txt'); print MYFILE "$str\n"; close (MYFILE); } # End while close(DATA)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: writing all the strings between two particular substrings
by CountZero (Bishop) on Oct 28, 2009 at 07:27 UTC | |
|
Re: writing all the strings between two particular substrings
by FalseVinylShrub (Chaplain) on Oct 28, 2009 at 06:23 UTC | |
by Anonymous Monk on Oct 28, 2009 at 06:47 UTC | |
|
Re: writing all the strings between two particular substrings
by bichonfrise74 (Vicar) on Oct 28, 2009 at 17:20 UTC |