bt707
asked on
join lines and print
I have a small script, getting the info I want just not being able to get the format I want. I believe I need to
join the results I have but not getting that to work.
I have a file with lines in it such as:
Date is 200710010300
Total number of calendars: 10792
Total number of events: 2374732
Total number of tasks: 68125
Date is 200710020300
Total number of calendars: 10828
Total number of events: 2373163
Total number of tasks: 68119
Date is 200710030300
Total number of calendars: 10848
Total number of events: 2381772
Total number of tasks: 68096
My script is like this:
#!/usr/bin/perl
use strict;
open (IN, "totals.txt") or die qq{Failed to open file -- $!};
while (<IN>) {
chomp;
next if /^\s*$/;
my ($date) = (/Date is\s(.*?)$/);
my ($cals) = (/Total number of calendars:\s(.*?)$/);
my ($events) = (/Total number of events:\s(.*?)$/);
my ($tasks) = (/Total number of tasks:\s(.*?)$/);
####print IN join(qq{\t},qw{$date $cals $events $tasks});
print "$date\n" if $date;
print "$cals\n" if $cals;
print "$events\n" if $events;
print "$tasks\n" if $tasks;
}
It will print out now like this:
200710010300
10792
2374732
68125
200710020300
10828
2373163
68119
200710030300
10848
2381772
68096
What I want is for it to print out like
200710010300 10792 2374732 68125
200710020300 10828 2373163 68119
200710030300 10848 2381772 68096
I would think I just need to take my results and join them but not doing it right.
Thanks,
join the results I have but not getting that to work.
I have a file with lines in it such as:
Date is 200710010300
Total number of calendars: 10792
Total number of events: 2374732
Total number of tasks: 68125
Date is 200710020300
Total number of calendars: 10828
Total number of events: 2373163
Total number of tasks: 68119
Date is 200710030300
Total number of calendars: 10848
Total number of events: 2381772
Total number of tasks: 68096
My script is like this:
#!/usr/bin/perl
use strict;
open (IN, "totals.txt") or die qq{Failed to open file -- $!};
while (<IN>) {
chomp;
next if /^\s*$/;
my ($date) = (/Date is\s(.*?)$/);
my ($cals) = (/Total number of calendars:\s(.*?)$/);
my ($events) = (/Total number of events:\s(.*?)$/);
my ($tasks) = (/Total number of tasks:\s(.*?)$/);
####print IN join(qq{\t},qw{$date $cals $events $tasks});
print "$date\n" if $date;
print "$cals\n" if $cals;
print "$events\n" if $events;
print "$tasks\n" if $tasks;
}
It will print out now like this:
200710010300
10792
2374732
68125
200710020300
10828
2373163
68119
200710030300
10848
2381772
68096
What I want is for it to print out like
200710010300 10792 2374732 68125
200710020300 10828 2373163 68119
200710030300 10848 2381772 68096
I would think I just need to take my results and join them but not doing it right.
Thanks,
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
That's just what I was trying to do, I just put the tabs back in and got just what I needed, I was just using the tabs so I could send the output to a xls file and be able to read the results from a excel file.
Still have a long, long way to go but at least I learn some things from here.
Thanks again!