Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Altering data files

by systems (Pilgrim)
on Oct 12, 2006 at 16:16 UTC ( #577895=note: print w/replies, xml ) Need Help??

in reply to Altering data files

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.
  1. Read the file into an array.
  2. Find the array index where you find: "StrCatDone" "1". Using the for(;;) loop.
  3. Modify the array element of the next index hence the ++$i.
  4. 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;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://577895]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2016-10-28 22:48 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (387 votes). Check out past polls.