in reply to Re: Extract string to file
in thread Extract string to file
Thank you for the reply. I forgot to add my final solution here. I tried modifying my previous post question solution with the quotemeta as you had suggested but it did not seem to be working for me. While it has the warning, it does still provide the needed output.
On this post your suggestions worked great. I simply added a slight modification so that I could set an input file and output to a file instead of onscreen. Here is what I ended up with.
use warnings; use strict; ## Select input and output files my $input_file = 'InputFile.OH1'; my $output_file = 'OutputFile.csv'; open my $ifh, "<", $input_file or die "cannot open '$input_file' for reading: $!\n"; open my $ofh, ">", $output_file or die "cannot open '$output_file' for writing: $!\n"; ## Creates a header at the beginning of the file my $header = "HEC1_ID,Q100_Base,TTP,Area\n"; print $ofh $header; ## Extracts data from input and sends through STDOUT to output file select $ofh; while (<$ifh>) { s{ ^ # at the beginning of the line \+ # followed by literal plus (?:\s+(\S+)) # column one (?:\s+(\S+)) # column two (?:\s+(\S+)) # column three (?:\s+\S+){3} # skip three columns \s+(\S+)$ # catch the last one, too }{$1,$2,$3,$4}x and print; } select STDOUT;
Once again, thanks for the help
|
---|