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

UUSWCMMHKFQU at spammotel.com UUSWCMMHKFQU at spammotel.com
Tue Mar 20 11:28:23 EST 2007


Re: a book.  _Learning Perl_, by Schwartz and Phoenix; O'Reilly pub.
Now in its 3rd edition, if you want to save money you can get a
previous edition very cheap at half.com or allbookstores.com.  This is
one of the better teaching books I've read, it comes from the authors'
experiences teaching perl classes.

To solve this problem, bacause of the "on and on..." you probably need
to save each row ($R1, $R2, $R3) AND save the fields in each row
($R1[0], $R1[1], $R2[0]...), so you have each element on the original
page available to save in the resulting new page.

Here is one way to do it which is easier for a beginner to read and
maintain.  It avoids using two-dimensional arrays, which are
error-prone to manipulate.

Save it as tsv2rt.pl, and run it in the same directory as your
tsv_filename.tsv with this command, to read in its input from
tsv_filename.tsv, and create a new file called rt_ticket.txt

perl tsv2rt.pl < tsv_filename.tsv > rt_ticket.txt

---BEGIN PERL---
#read in all rows from .tsv file and store in array @rows, one row per
array element
@rows = <>;

#now row A from your email is stored in $rows[0],
#row B is stored in $rows[1], etc.  Explicitly save each one
#of the 23 rows as an array of row elements like this:

#split the contents of the first row on the tab character
#store the resulting array of elements in @A
@A = split /\t/, $rows[0];
@B = split /\t/, $rows[1];
@C = split /\t/, $rows[2];

#...repeat for all 23 rows. You're typing more here, to make typing
the report itself
#less error-prone

#print the report
#make sure the terminating string END_OF_REPORT
#is not indented the bottom of the report.

print <<END_OF_REPORT;
===Create-Ticket: ticket1
Queue: $B[1]
Subject: $C[1]
Status: $D[1]
etc...
END_OF_REPORT

---END PERL---

On 3/20/07, Gentgeen <gentgeen at linuxmail.org> wrote:
>
>
>
> 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