You already had good and wise answers but if you need to surprise or just want to learn more, Perl can handle this situation in few keystroke (see
perlrun for details); given the following
inputtable.txt file:
Client|Counts by Month
IBM | February 1 March 5 July 4
Oracle| January 3 March 4 April 6 May 5
RedHat | March 2 June 3 August 1
you can tame it at your will with:
# warning windows double quotes!
perl -MData::Dump -F"\s*\|\s*|\s" -lane "next if $.==1;$r{$F[0]}={@F[1
+..$#F]};END{dd %r}" inputtable.txt
(
"IBM",
{ February => 1, July => 4, March => 5 },
"Oracle",
{ April => 6, January => 3, March => 4, May => 5 },
"RedHat",
{ August => 1, June => 3, March => 2 },
)
or if you prefere the core module Data::Dumper you'll end with a longer version:
perl -MData::Dumper -F"\s*\|\s*|\s" -lane "next if $.==1;$r{$F[0]}={@F
+[1..$#F]};END{print Dumper \%r}" i
nputtable.txt
$VAR1 = {
'IBM' => {
'February' => '1',
'July' => '4',
'March' => '5'
},
'Oracle' => {
'March' => '4',
'May' => '5',
'January' => '3',
'April' => '6'
},
'RedHat' => {
'June' => '3',
'March' => '2',
'August' => '1'
}
};
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.