in reply to replace a column
and the following replacement file:1:2:3:4 5:6:7:8 :9:10:11 12:13:14:15 :17:18:19
The following code replace the first column (for simplicity sake) in the original file with the first column in the replacement file (according to the assumptions about your requirements I made above).a:b:c:d:e f:g:h:i:j k:l:m:n:o p:q:r:s:t u:v:w:x:y
contents of orginal file after program is run:use File::Copy; use strict; my (@col, $val, $i); open(COL, "<replace.txt"); while(<COL>) { push @col, $_ =~ m/(.*?):/; } close(COL); open(OUT, ">out.txt"); open(COL, "<original.txt"); while(<COL>) { ($val) = $_ =~ m/(.*?):/; $_ =~ s/(.*?)(?=:)/$col[$i++]/ unless $val =~ m/^\s*$/; print OUT $_; } close(COL); close(OUT); copy("out.txt", "original.txt");
Again, this may or may not be what you want since you were not specific in the meaning of "in the same format as the original".a:2:3:4 f:6:7:8 :9:10:11 k:13:14:15 :17:18:19
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: replace a column
by Anonymous Monk on Jul 06, 2004 at 14:28 UTC | |
by davidj (Priest) on Jul 06, 2004 at 15:03 UTC | |
by Anonymous Monk on Jul 06, 2004 at 14:37 UTC | |
by Anonymous Monk on Jul 06, 2004 at 15:01 UTC |