D
droman
Hello,
I'm trying to write a script to do a fairly complicated substitution in
a large number of text files. The third line of each text file reads
something like
"1995-09-25S.IRIG_CHT 6".
The '1995-09-25S.' part of this line is different in each file, but the
rest of the line is identical in all files. What I need to do is add
(as the forth, fifth, etc. lines) several lines to each file in which
the '1995-09-25S.' is the same on each line but the 'IRIG_CHT' part is
different, so that from the third line the file reads
"1995-09-25S.IRIG_CHT 6
1995-09-25S.MBET_CHT 6
1995-09-25S.MGAT_CHT 6
..."
I'm trying to do this as a substitution. So for each file, I read the
'1995-09-25S.' part of the third line into a variable ($date) and then
I try to substitute as follows:
s/$dateIRIG_CHT 6/$dateIRIG_CHT 6\n$dateMBET_CHT 6\n.../i;
Obviously, I'm a Perl newbie and am getting the syntax wrong or using
substitution for too difficult of a task, because I can't get it to
work. Is it possible to use substitution in Perl to substitute long,
multi-line strings containing a combination of text and variables? If
so, any ideas on what I've done wrong?
Thanks much.
I'm trying to write a script to do a fairly complicated substitution in
a large number of text files. The third line of each text file reads
something like
"1995-09-25S.IRIG_CHT 6".
The '1995-09-25S.' part of this line is different in each file, but the
rest of the line is identical in all files. What I need to do is add
(as the forth, fifth, etc. lines) several lines to each file in which
the '1995-09-25S.' is the same on each line but the 'IRIG_CHT' part is
different, so that from the third line the file reads
"1995-09-25S.IRIG_CHT 6
1995-09-25S.MBET_CHT 6
1995-09-25S.MGAT_CHT 6
..."
I'm trying to do this as a substitution. So for each file, I read the
'1995-09-25S.' part of the third line into a variable ($date) and then
I try to substitute as follows:
s/$dateIRIG_CHT 6/$dateIRIG_CHT 6\n$dateMBET_CHT 6\n.../i;
Obviously, I'm a Perl newbie and am getting the syntax wrong or using
substitution for too difficult of a task, because I can't get it to
work. Is it possible to use substitution in Perl to substitute long,
multi-line strings containing a combination of text and variables? If
so, any ideas on what I've done wrong?
Thanks much.