format - Formating parsed output perl -


so yeah have file - alli need last 5 lines file. know not supposed parse html without html module. not reallly program strict - mean need last 5 lines or so. besides cannot donwload modules. have access proxy server allows me curl files command line maybe there way use cpan fromteh or throught proxy - nother matter. matter @ hand when parse out thelast file lines or so, dont "names in my-dept restricted" , want it. gets skipped.

new_guy@casper0170foo:~/hey/hit_bank_restricted.$ cat restricted.html.bak to:dl-bank@big_business.com from:dl-dept?g-gsd-stm@big_business.com subject: restricted list 25-nov-2014 content-type: text/html; content-transfer-encoding: quoted-print htmlfileable> <html>   <head>      <style type="text/css">      body    { font-family: verdana; font-size: 10pt }      td      { font-size: 8pt; vertical-align: top }      td.cat  { color: 6699ff ; background: 666699; text-align: right; vertical-align: bottom; height: 30 }      td.ind  { width: 20pt }      td.link { }      td.desc { color: a0a0a0 }      a:visited { color: 800080; text-decoration: none }     </style>  <title>trades</title>  </head><body><table width="80%" border="0" cellpadding="0" cellspacing="0">       <tr>          <td colspan="3" align="center">names in my-dept restricted</td>       </tr>       <tr>         <td><b>restriction code</b></td>         <td><b>company</b></td>         <td><b>ticker</b></td>      </tr><tr><td>rl5</td><td>first trust global risk managed inc</td><td>etp</td></tr><font color="red"><tr><td>rlmt</td><td>gt advanced technologies inc</td><td nowrap>gtatq (position only, not in my-dept)</td></tr></font></table></body</html>new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ cat parse_restrict2 #!/usr/bin/perl use strict; use warnings ; @restrict_codes = qw(rl3 rl5 rl5h rl6 regm raf rlmt rtca rtcah rtcb rtcbh rtci rtcih rlsi rlhk rljp rprop rlcb rlcs rlbz rlbzh rlsus); $rest_dir = "/home/new_guy/hey/hit_bank_restricted./"; $restrict_file = "restricted.html.bak" ; open $fh_rest_codes, '<', "$rest_dir$restrict_file" or die "cannot load $! " ; while (<$fh_rest_codes>) {     next unless $_ =~ m/names/;     @lines = <$fh_rest_codes> ;     } foreach(@lines) {     s/td/ /g ;     s/<[^>]*>/ /g ;     foreach $restrict(@restrict_codes) {         s/$restrict/\n$restrict/g;         }     print $_ ;     sleep 1  ;     }  print "\n" ; 

these results get: ok format them , not know how.

new_gue@casper0170foo:~/hey/hit_bank_restricted.$ cat parse_restrict^c new_guy@casper0170foo:~/hey/hit_bank_restricted.$ ./parse_restrict2             restriction code           company           ticker  rl5  first trust global risk managed inc  etp rlmt  gt advanced technologies inc  gtatq (position only, not in my-dept) new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ new_guy@casper0170foo:~/hey/hit_bank_restricted.$ 

would there way possible lines in kind of format.

names in my-dept restricted  restriction code company                              ticker rl5              first trust global risk managed inc  etp rlmt             gt advanced technologies inc         gtatq (position only, not in my-dept) 

good question, try workaround if like:

my @lines; while (<$fh_rest_codes>) {     next unless $_ =~ m/names/;     push(@lines, $_);     push (@lines, <$fh_rest_codes>); } $str=join ('',@lines);     $str=~m|<td.*?>(.*?)</td>|;     print "$1\n\n"; $str=~ m|<tr>(.*?)</tr>|msg; $fmt="%-24s%-40s%-40s\n"; printf ($fmt,  $1=~ m{<td><b>(.*?)</b></td>}msg ); while ($str=~ m|<tr>(.*?)</tr>|msg) {     printf ($fmt,  $1=~ m{<td.*?>(.*?)</td>}msg ); } 

output:

names in my-dept restricted  restriction code        company                                 ticker                                   rl5                     first trust global risk managed inc     etp                                      rlmt                    gt advanced technologies inc            gtatq (position only, not in my-dept)    

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -