I need to split a file into different ones.
Exmaple (original file):
*****3123123*****RAW
text1
text2
*****2312354***RAW
text3
Desired output:
[File1.txt]
*****3123123*****RAW
text1
text2
[File2.txt]
*****312312354***RAW
text3
I tried to use split, but I always get some extra white characters into the array
open FILE, "<file";
@file= <FILE>;
close FILE;
@lines = split (/(RAW\n)/, "@file");
foreach $value (@lines) {
if ($value =~ /[a-z]|[A-Z]|[1-9]/) {
print ("$value\n");
}
}
Output:
*****3123123*****RAW
text1
text2
*****312312354***RAW
text3
Edit: if I use print (“$value”) instead of print (“$value\n”) this is the output (notice the 1 extra space before the value:
*****3123123*****RAW
text1
text2
*****12354***RAW
text3
This program pulls the decimal number from the
RAWline and uses it to name the output files. It expects the input file name as a parameter on the command line.