Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

improved parsing out to .htm

Status
Not open for further replies.

nanohurtz

Programmer
Mar 25, 2002
15
US
I've written a script that will read an 8 part string that starts with the word -alias-. It extracts the 2nd, 6th and 8th variable and prints it out to htm with count in a table format.

example:
I have 3 problems
One. I would like to further isolate the actual alias word by eliminating the characters starting with the (equal) character in the $varalias string.

Two. I'd also like to be able to parse out the " (quotation) characters in the $vartarget string. The end result would look something like the following example

example:
This way I can use the $varsource and $vartarget variable in other file and directory sub routines

Three. The trickiest, there are times when the input file may contain carriage returns between my wanted strings. Is there a way I can filter them out within the same perl routine?

example: alias tt_clms_copy="/usr/cmvc/cmtools/bin/cm_move.sh -e /cmtest/appsmore/27/hpux/text/cmexports -t /cmtest/appsmore/27/hpux -s /prod1/uat_stage/clmstux/ap_clms"

Attached is the code.

Code:
open(IN, &quot;< prevplanin.txt&quot;);
open(OUT, &quot;> prevplanout.htm&quot;);
my ($varalias, $varsource, $vartarget);

print OUT &quot;<html><head><title>PLAN VERIFICATION</title></head><body bgcolor=\&quot;\#FFFFFF\&quot; text=\&quot;\#000000\&quot;>&quot;;
$i = 1;
while(<IN>) {
chomp;
if (m/(alias) (.*) (.*) (.*) (.*) (.*) (.*) (.*)$/) {
$varalias=$2, $varsource=$6, $vartarget=$8;

print OUT &quot;<table width=\&quot;37%\&quot; border=\&quot;0\&quot; cellspacing=\&quot;1\&quot; cellpadding=\&quot;0\&quot;><tr bgcolor=\&quot;\#0099CC\&quot;><td colspan=\&quot;2\&quot;><font face=\&quot;Geneva, Arial, Helvetica, san-serif\&quot; size=\&quot;2\&quot;><b>&quot;;
print OUT &quot;<font color=\&quot;\#FFFFFF\&quot;>alias retrieved</font></b></font></td></tr><tr><td width=\&quot;11%\&quot; bgcolor=\&quot;\#CCCCCC\&quot;><font face=\&quot;Geneva, Arial, Helvetica, san-serif\&quot; size=\&quot;2\&quot;><b>&quot;;
print OUT &quot;alias</b></font></td><td width=\&quot;89%\&quot; bgcolor=\&quot;\#FFCC99\&quot;><font face=\&quot;Geneva, Arial, Helvetica, san-serif\&quot; size=\&quot;2\&quot;>$varalias</font></td></tr><tr><td width=\&quot;11%\&quot; bgcolor=\&quot;\#CCCCCC\&quot;>&quot;;
print OUT &quot;<font face=\&quot;Geneva, Arial, Helvetica, san-serif\&quot; size=\&quot;2\&quot;><b>source</b>&quot;;
print OUT &quot;</font></td><td width=\&quot;89%\&quot; bgcolor=\&quot;\#FFCC99\&quot;><font face=\&quot;Geneva, Arial, Helvetica, san-serif\&quot; size=\&quot;2\&quot;>$varsource</font></td></tr><tr><td width=\&quot;11%\&quot; bgcolor=\&quot;\#CCCCCC\&quot;>&quot;;
print OUT &quot;<font face=\&quot;Geneva, Arial, Helvetica, san-serif\&quot; size=\&quot;2\&quot;><b>target</b></font></td><td width=\&quot;89%\&quot; bgcolor=\&quot;\#FFCC99\&quot;><font face=\&quot;Geneva, Arial, Helvetica, san-serif\&quot; size=\&quot;2\&quot;>$vartarget</font></td></tr><tr><td colspan=\&quot;2\&quot; bgcolor=\&quot;\#0099CC\&quot;>&quot;;
print OUT &quot;<font face=\&quot;Geneva, Arial, Helvetica, san-serif\&quot; size=\&quot;2\&quot;><b><font color=\&quot;\#FFFFFF\&quot;>$i</font></b></font></td></tr></table><p></p>&quot;;

$i = $i + 1;
}
print OUT &quot;</body></html>&quot;
}
close(IN);
close(OUT);

Any help is greatly appreciated. Thanks.
 
I think this would take care of 1 and 2.

while(<IN>) {
chomp;
my ($varalias) = /alias\s+(.+?)=/;
my ($varsource) = /\-s\s+(.+?)[\s&quot;]/;
my ($vartarget) = /\-t\s+(.+?)[\s&quot;]/;

# etc ...

One comment on that. From the input example you gave I assumed that the '-t' flag meant 'target' and the '-s' flag meant 'source'. From your example page of out put it appeared that these were reversed. Did I assume wrong? If so swap the '-s' and '-t' in the regexes.

As for point 3, could you be more specific about what you mean? When you say 'between my wanted strings' you mean there might be a newline between the quotes?

jaa
 
Thanks justice, very helpful. I was able to fix the $varsource and $vartarget issue using
Code:
 $varalias =~ s/=.*//g; $vartarget =~ s/&quot;//g;
. The carriage returns though elude me.

Here's a sample in string
Code:
 alias tq_test_line=&quot;/usr/cmvc/cmtools/bin/cm_move.sh -e cmtest/appsmore/27/hpux/text/cmexports -t
 /cmtest/appsmore/27/hpux -s 
/prod1/uat_stage/clmstux/ap_clms&quot;

This nasty critter has two to three carriage returns which I tried stripping with
Code:
 s/\n/ /g;
but it blows up in my face. Maybe I need to modify the regexp
Code:
 if (m/(alias) (.*) (.*) (.*) (.*) (.*) (.*) (.*)$/)
to strip carriage returns first then filter for the desired variables. Does you know how to return a &quot;not found&quot; statement for any variables not initialized as a result of failing the regexp filter. Again any help is greatly appreciated!
 
this is the sample input string again

Code:
 alias tq_test_line=&quot;/usr/cmvc/cmtools/bin/cm_move.sh -e cmtest/appsmore/27/hpux/text/cmexports -t
 /cmtest/appsmore/27/hpux -s 
/prod1/uat_stage/clmstux/ap_clms&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top