We help IT Professionals succeed at work.

join lines and print

bt707
bt707 asked
on
1,927 Views
Last Modified: 2008-02-07
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,
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks mjcoyne,

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!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.