format fil

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi I have a file that looks like this.

12,1427766557, bob
22,1427762457, bill
53,1427769753, bob

I'd like to format it like this

bob                              bill
1427766557   12      1427762457   22
1427769753   53

I'm not sure how to approach this. Help please.

Re: format fil wrote:
Quoted text here. Click to load it

What have you tried so far? Where did you get stuck?

Anyway, here are some thoughts:
- because you are doing a transposition of the matrix you need to read
the whole matrix into memory before you can write out the first result
- read the file line by line, splitt()ing each line into it's components
and store the items in a hash using the names 'bill' and 'bob' as keys
and store the numbers in an array of array as value for each hash entry
- then for the first output line loop over keys of the hash and print
- and for each following line loop over the values of the hash and print
the n-th item of each array


Re: format fil

On 17.04.15 02:55, wrote:
Quoted text here. Click to load it

Alternatively, perform the transformation in several passes.
That's necessary in particular when less RAM is available
than the amount of data would require.

First, collect the necessary information by comparing the
current line's values to what was learned from looking at
lines before the current one.

Second, use that information for manipulating the lines
during a second pass.

Re: format fil

El 17/04/15 a las 11:36, Georg Bauhaus escribió:
Quoted text here. Click to load it

I only want to add that if the OP wants a final pretty
format he could look at the Perl6::Forms module. It is
said that perl5 format op is obsolete.

The generation of random numbers is too important to be left to chance

Site Timeline