On Thursday 20 December 2007 07:49, banker123 wrote:
>
> I have a text file with a ragged hierarchy as shown below, I would
> like to structure the data in a different format (also shown below)
> please help.  Also the data below is just an example the actual data
> file is much larger and the hierarchy has 10 levels the lowest level
> "Employee" could be stored anywhere wtihin the 10 levels depeding
> upon the business units structure.  I have not used Perl in about 6
> months but if memory serves me correctly Perl is the perfect tool for
> the job.
>
> Original
> Company     Business Unit1     Employee1
> Company     Business Unit1     Business Unit2     Employee2
>
>
> New
> Employee1     Company     Business Unit1
> Employee2     Company     Business Unit1     Business Unit2


$ echo "Company     Business Unit1     Employee1
Company     Business Unit1     Business Unit2     Employee2" |\
perl -lne'
my ( $co, @data ) = split /\s{2,}/;
my ( $bu, $empl ) = splice @data, -2;
printf q[%-14s%-12s] . ( q[%-19s] x @data ) . qq[%s\n], $empl, $co, 
@data, $bu;
'
Employee1     Company     Business Unit1
Employee2     Company     Business Unit1     Business Unit2




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to