Okay this is complex. But, if you have the patience just to nudge me in the right direction. I know I am close...
I have a file. Format of file is:
Line starts with ST: SIGNAL_NAME1, SIGNAL_NAME2
.
.
.
Line starts with YZ: WO RD 1, WO RD 2, WO RD 3, WO RD 4,
Line starts with YZ: WO RD 5, WO RD 6, WO RD 7, WO RD 8.
.
.
.
[[although lines below are beginning of new data of same experiment they are joined with the above one]]
Line starts with ST: SIGNAL_NAME3, SIGNAL_NAME4
.
.
.
Line starts with YZ:new WORD 9,new WORD 10,new WORD 11,new WORD 12,
Line starts with YZ:new WORD 13,new WORD 14,new WORD 15,new WORD 16.
.
.
.
and so on...
I need to change this file to the following format:
SIGNAL_NAME 1 WORD 1
SIGNAL_NAME 1 WORD 2
SIGNAL_NAME 1 WORD 3
SIGNAL_NAME 1 WORD 4
SIGNAL_NAME 1 WORD 5
SIGNAL_NAME 1 WORD 6
SIGNAL_NAME 1 WORD 7
SIGNAL_NAME 1 WORD 8
SIGNAL_NAME 2 WORD 1
SIGNAL_NAME 2 WORD 2
SIGNAL_NAME 2 WORD 3
SIGNAL_NAME 2 WORD 4
SIGNAL_NAME 2 WORD 5
SIGNAL_NAME 2 WORD 6
SIGNAL_NAME 2 WORD 7
SIGNAL_NAME 2 WORD 8
SIGNAL_NAME 3 WORD 9
SIGNAL_NAME 3 WORD 10
SIGNAL_NAME 3 WORD 11
SIGNAL_NAME 3 WORD 12
SIGNAL_NAME 3 WORD 13
SIGNAL_NAME 3 WORD 14
SIGNAL_NAME 3 WORD 15
SIGNAL_NAME 3 WORD 16
SIGNAL_NAME 4 WORD 9
SIGNAL_NAME 4 WORD 10
SIGNAL_NAME 4 WORD 11
SIGNAL_NAME 4 WORD 12
SIGNAL_NAME 4 WORD 13
SIGNAL_NAME 4 WORD 14
SIGNAL_NAME 4 WORD 15
SIGNAL_NAME 4 WORD 16
But, I am getting...
SIGNAL_NAME 1 WORD 1
SIGNAL_NAME 1 WORD 2
SIGNAL_NAME 1 WORD 3
SIGNAL_NAME 1 WORD 4
SIGNAL_NAME 2 WORD 1
SIGNAL_NAME 2 WORD 2
SIGNAL_NAME 2 WORD 3
SIGNAL_NAME 2 WORD 4
SIGNAL_NAME 3 WORD 9
SIGNAL_NAME 3 WORD 10
SIGNAL_NAME 3 WORD 11
SIGNAL_NAME 3 WORD 12
SIGNAL_NAME 4 WORD 9
SIGNAL_NAME 4 WORD 10
SIGNAL_NAME 4 WORD 11
SIGNAL_NAME 4 WORD 12
SIGNAL_NAME 1 WORD 5
SIGNAL_NAME 1 WORD 6
SIGNAL_NAME 1 WORD 7
SIGNAL_NAME 1 WORD 8
SIGNAL_NAME 2 WORD 5
SIGNAL_NAME 2 WORD 6
SIGNAL_NAME 2 WORD 7
SIGNAL_NAME 2 WORD 8
SIGNAL_NAME 3 WORD 13
SIGNAL_NAME 3 WORD 14
SIGNAL_NAME 3 WORD 15
SIGNAL_NAME 3 WORD 16
SIGNAL_NAME 4 WORD 13
SIGNAL_NAME 4 WORD 14
SIGNAL_NAME 4 WORD 15
SIGNAL_NAME 4 WORD 16
The separations seem to come from me reading each newline. Is there anyway I can just group together the lines from one file (from ST to the end)? And then, split?
my code is as follows.
I have a file. Format of file is:
Line starts with ST: SIGNAL_NAME1, SIGNAL_NAME2
.
.
.
Line starts with YZ: WO RD 1, WO RD 2, WO RD 3, WO RD 4,
Line starts with YZ: WO RD 5, WO RD 6, WO RD 7, WO RD 8.
.
.
.
[[although lines below are beginning of new data of same experiment they are joined with the above one]]
Line starts with ST: SIGNAL_NAME3, SIGNAL_NAME4
.
.
.
Line starts with YZ:new WORD 9,new WORD 10,new WORD 11,new WORD 12,
Line starts with YZ:new WORD 13,new WORD 14,new WORD 15,new WORD 16.
.
.
.
and so on...
I need to change this file to the following format:
SIGNAL_NAME 1 WORD 1
SIGNAL_NAME 1 WORD 2
SIGNAL_NAME 1 WORD 3
SIGNAL_NAME 1 WORD 4
SIGNAL_NAME 1 WORD 5
SIGNAL_NAME 1 WORD 6
SIGNAL_NAME 1 WORD 7
SIGNAL_NAME 1 WORD 8
SIGNAL_NAME 2 WORD 1
SIGNAL_NAME 2 WORD 2
SIGNAL_NAME 2 WORD 3
SIGNAL_NAME 2 WORD 4
SIGNAL_NAME 2 WORD 5
SIGNAL_NAME 2 WORD 6
SIGNAL_NAME 2 WORD 7
SIGNAL_NAME 2 WORD 8
SIGNAL_NAME 3 WORD 9
SIGNAL_NAME 3 WORD 10
SIGNAL_NAME 3 WORD 11
SIGNAL_NAME 3 WORD 12
SIGNAL_NAME 3 WORD 13
SIGNAL_NAME 3 WORD 14
SIGNAL_NAME 3 WORD 15
SIGNAL_NAME 3 WORD 16
SIGNAL_NAME 4 WORD 9
SIGNAL_NAME 4 WORD 10
SIGNAL_NAME 4 WORD 11
SIGNAL_NAME 4 WORD 12
SIGNAL_NAME 4 WORD 13
SIGNAL_NAME 4 WORD 14
SIGNAL_NAME 4 WORD 15
SIGNAL_NAME 4 WORD 16
But, I am getting...
SIGNAL_NAME 1 WORD 1
SIGNAL_NAME 1 WORD 2
SIGNAL_NAME 1 WORD 3
SIGNAL_NAME 1 WORD 4
SIGNAL_NAME 2 WORD 1
SIGNAL_NAME 2 WORD 2
SIGNAL_NAME 2 WORD 3
SIGNAL_NAME 2 WORD 4
SIGNAL_NAME 3 WORD 9
SIGNAL_NAME 3 WORD 10
SIGNAL_NAME 3 WORD 11
SIGNAL_NAME 3 WORD 12
SIGNAL_NAME 4 WORD 9
SIGNAL_NAME 4 WORD 10
SIGNAL_NAME 4 WORD 11
SIGNAL_NAME 4 WORD 12
SIGNAL_NAME 1 WORD 5
SIGNAL_NAME 1 WORD 6
SIGNAL_NAME 1 WORD 7
SIGNAL_NAME 1 WORD 8
SIGNAL_NAME 2 WORD 5
SIGNAL_NAME 2 WORD 6
SIGNAL_NAME 2 WORD 7
SIGNAL_NAME 2 WORD 8
SIGNAL_NAME 3 WORD 13
SIGNAL_NAME 3 WORD 14
SIGNAL_NAME 3 WORD 15
SIGNAL_NAME 3 WORD 16
SIGNAL_NAME 4 WORD 13
SIGNAL_NAME 4 WORD 14
SIGNAL_NAME 4 WORD 15
SIGNAL_NAME 4 WORD 16
The separations seem to come from me reading each newline. Is there anyway I can just group together the lines from one file (from ST to the end)? And then, split?
my code is as follows.
Code:
foreach $sign (@data1) { #data1 is array containing data
if ($sign =~ /^ST/) { #ST at beginning signifies a new file
$signal = $sign; #this means the line is a SIGNAL line
$signal =~ s/ST//g; #remove ST abbreviation
$signal =~ s/^\s+//; #remove leading whitespace
$signal =~ s/\s+$//;
$signal =~s/\s//g;
@light = split(';', $signal);
}
foreach $ray (@light) {
if ($sign =~ /^YZ/) {
$krypton = $sign;
$krypton =~ s/YZ//g;
$krypton =~ s/^\s+//;
$krypton =~ s/\s+$//;
$krypton =~ s/\.//g;
@meteor = split(';', $krypton);
foreach (@meteor){
$meteor = "$_";
$meteor =~ s/^\s+//;
$news = "$ray $meteor\n";
}
}
}
}