[wplug] Scripting - Text file manipulation help - probably perl

smk at fyi.net smk at fyi.net
Tue Mar 20 10:07:59 EST 2007


You can do this a number different ways.

use strict;
use warnings;

open my $file, "<", "file" or die "Cannot open file: $!" # change 'file'
actual file
my @data = <$file>;
close $file;

open my $outfile, ">", "outfile.txt" or die "Cannot open file for writing:
$!;

for my $entry (@data) {

     print $outfile "Queue: $data[0]\n";



>
> I need a bit of help changing a tab-delimited document (.tsv file) into
> a special format so I can import it into our trouble ticket system (RT).
>
> The .tsv file has 23 columns, and 108 entries.  I am going to use a
> spreadsheet style to reference the values (i.e. A1 for the 1st column,
> 1st entry - B1 for the 2nd column, 1st entry)
>
> I need to get it into a text file that would look like this:
>
> ===Create-Ticket: ticket1
> Queue: <B2>
> Subject: <C2>
> Status: <D2>
> TimeEstimated: <E2>
> TimeWorked: <F2>
> TimeLeft: <G2>
> Priority: <H2>
> FinalPriority: <I2>
> Owner: <J2>
> Requestors: <K2>
> Due: <L2>
> Told: <M2>
> Created: <N2>
> Resolved: <O2>
> CustomField-10: <P2>
> CustomField-11: <Q2>
> CustomField-12: <R2>
> CustomField-13: <S2>
> CustomField-14: <T2>
> CustomField-5: <U2>
> CustomField-7: <V2>
> CustomField-8: <W2>
> CustomField-9: <X2>
>
> ===Create-Ticket: ticket1
> Queue: <B3>
> Subject: <C3>
> Status: <D3>
>
> on, and on, and on.....
>
>
>
> Knowing that (most likly) the suggestion will come back as a PERL
> solution... I would also like to request any suggesting for a good PERL
> book.  PERL for dummys kind of thing (My coding/scripting skills are
> limited to bash and HTML, not exactly very fancy stuff :-)  )
>
> Thanks in advance for your time.
>
> --
> http://gentgeen.homelinux.org
>
> #############################################################
>  Associate yourself with men of good quality if you esteem
>  your own reputation; for 'tis better to be alone then in bad
>  company.        - George Washington, Rules of Civility
> _______________________________________________
> wplug mailing list
> wplug at wplug.org
> http://www.wplug.org/mailman/listinfo/wplug
>




More information about the wplug mailing list