I wish to loop through multiple files, and their respective lines in the file. I have done is successfully already. Want I want to do now is remove lines in a file based on a numeric value in one of the columns. If I have an input such as this:
XP.sta1 -41.5166 0.0513 0.6842 0.1794 0 CPHI.BHZ 300 +.2458 -42.2436 XP.sta2 3.5972 0.0500 0.7699 0.1213 0 E000.BHZ 30 +0.5616 2.5545 XP.sta3 3.7112 0.0267 0.7813 0.1457 0 E002.BHZ 30 +0.6140 2.6160 XP.sta4 4.2891 0.0214 0.6870 0.1308 0 E004.BHZ 30 +1.2073 2.6006
I want to remove the line IF the 8th column numeric value is < -10 or > 10. Here's my code so far:
open(TABLEC,$mFile); @tablec = <TABLEC>; for ($j = 2; $j < $stop; $j++) { chomp ($tablec[$j]); ($netSta,$delayTime) = (split /\s+/,$tablec[$j])[1,9]; next if $delayTime < -10 or $delayTime > 10;
I am reading through multiple files, and for lines in between 2 and "stop" I want to remove that line if the 8th column value is <-10 or > 10. From the input above, I want to remove the line beginning with XP.sta1, since the 8th column is -40. How do I do this without simply deleting the 8th column value? This script is slightly modified, but if I run with the above code structure, the output is this:
XP.sta1 -41.5166 0.0513 0.6842 0.1794 0 CPHI.BHZ 30 +0.2458 2.5545 XP.sta2 3.5972 0.0500 0.7699 0.1213 0 E000.BHZ 30 +0.5616 2.6160 XP.sta3 3.7112 0.0267 0.7813 0.1457 0 E002.BHZ 30 +0.6140 2.6006 XP.sta4 4.2891 0.0214 0.6870 0.1308 0 E004.BHZ 30 +1.2073
Where in the 8th column, that value of -42.4326 is removed, but not the entire line. How do I delete the entire line, rather than just the value in column 8? Thanks for the help.

In reply to Remove line from file based on numeric column value by Bama_Perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.