Below is my attempt. Some assumptions are made the most important is that "" "seq_name" will be one line below "StrCatDone".
Also note I am a Perl newbie, so the code below is not of good quality. Any my logic is.
- Read the file into an array.
- Find the array index where you find: "StrCatDone" "1". Using the for(;;) loop.
- Modify the array element of the next index hence the ++$i.
- write the array back to the file.
use strict;
use warnings;
my $file = shift @ARGV;
open (my $fh1, $file) or die "Can't open file \"$file\", $!";
my @txt = <$fh1>;
close $fh1;
my $newtext = '"seq_name" "sequence.V6.0"';
my $i;
for ($i=0; $i <= $#txt; $i++) {
last if $txt[$i]=~ m/"StrCatDone" "1"/;
#print $txt[$i];
}
$txt[++$i]="$newtext\n";
open (my $fh2,">$file") or die "Can't open file \"$file\", $!";
print $fh2 @txt;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.