in reply to Print record by column key

Check out Text::xSV by tilly, Text::ParseWords or Text::CSV_XS even.


Who says that programmers can't work in the Marketing Department?
Or is that who says that Marketing people can't program?

Replies are listed 'Best First'.
Re: Re: Print record by column key
by Anonymous Monk on May 13, 2002 at 03:27 UTC
    Hey thanks for the help!!! ^_^ Would know a way that I can remove the numbers and tabs between parenthesis of data stored in a file. I have tried using the grep command but it appeard to be greedy. It removes more info than needed. The following is an example of the data in the file: (The)<space>0<tab>257<tab>38(Name)<space>0<tab>501<tab>38() (Date)<space>1<tab>144<tab>94(REAL)<space>1<tab>65<tab>94() ( )<space>0<tab>2219<tab>2338(1120) (You Are Here) ( ) (Date)<space>0<tab>1447<tab>2571(today) How can I remove all data (numbers, tabs, and spaces) between each left and right parenthesis )remove( except for one <tab>,/t. Needed output: (The)<tab>(Name)<tab>() (Date)<tab>(REAL)<tab>() ( )<tab>(1120) (You Are Here) ( ) (Date)<tab>(today) Your help will be greatly appreciated.
      Since I can't really tell which characters are tabs and which are spaces, I'll give you a solution that will remove word characters.
      I'll let you figure out how to remove the tabs and spaces.
      #!/usr/bin/perl -w use strict; $line = "(The)025738(Name)050138()\t(Date)114494(REAL)16594()\t( )0221 +92338(1120)\t(You Are Here)\t( )\t(Date)014472571(today)\n"; $line =~ s/\)\w+\(/)(/g; # match on one or more word characters sandwi +ched between ) and ( print $line;

      Who says that programmers can't work in the Marketing Department?
      Or is that who says that Marketing people can't program?

        Hey,

        I gratefully thank you for your wisdom!

        Here is a very important question. If I have a file with variable length records, how can i make the records that same size?

        Ent, Name, SC011, BUN, Tester, Value, #1008 Ent, Name, FS0022L, FUN, TL0324, PLEASE, Tester, Value, #1002 Ent, Name, SC004, TAKE, K530, RUN, Tester, Value, #1001

        If the data between "Ent" and "Tester" are different as far as having one or two entries, how can I make the entries equal two and so on by adding new lines followed by commas. Each record in the file may have more than one entry between "Ent" and "Tester." If one record in the file has one entry between "Ent" and "Tester", and the others have eight, two, three,..... How would I alter each record with new lines to have the same number of lines. In the above case, the highest number would be two; but this could be higher in the file I have.

        Please help!

        Edit Petruchio Wed May 22 02:01:42 UTC 2002 - Added code tags, other markup.