I have a file called mail.txt in which lines are printed like below ,i want to put all those lines in to one single line like
Thanks
This is the input
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>
(host map: lookup (my.local.domain): deferred)
<[email protected]>
<[email protected]>
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>
(host map: lookup (my.local.domain): deferred)
<[email protected]>
<[email protected]>
This is the output
q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>,(host map: lookup (my.local.domain): deferred),<[email protected]>,<[email protected]> q2VDWKkY010407 2221878 Sat Mar 31 19:37 <Mailer-daemon>,(host map: lookup (my.local.domain): deferred), <[email protected]>,<[email protected]>
So why don't you just do it?
open(my $fh, "<", $input_filename);
my @lines = map { chomp; $_} <$fh>; #1
close $fh;
open(my $out, ">", $output_filename);
print $out join "", @lines; # or maybe a different separator, like ","
close $out;
#that's it
Note: if you want to get rid of the extra spaces at the beginnings and ends of input lines, you can replace line #1 by
my @lines = map { s/\s+$//; s/^\s+//; $_} <$fh>;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With