Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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;


Comment on Re: Altering data files
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2015-07-06 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls