Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Remove line from file based on numeric column value

by ww (Archbishop)
on May 26, 2015 at 12:10 UTC ( [id://1127809]=note: print w/replies, xml ) Need Help??


in reply to Remove line from file based on numeric column value

Canonical answer from aaron_baugher: Think in terms of writing your original content to a new file with some elements removed.

BUT, re your narrative: Your phrase "the 8th column" should be "the 9th column" because your removal target is column 9. Just so it's clear, column 9 is the 8th element, $dataline[8], of an array (@arr) formed by splitting

XP.sta1    -41.5166    0.0513    0.6842    0.1794    0  CPHI.BHZ   300.2458   -42.2436

on white space because "XP.sta1" is $line[0].

my $dataline = "XP.sta1 -41.5166 0.0513 0.6842 0.1794 0 + CPHI.BHZ 300.2458 -42.2436"; my @arr = split /\s+/, $dataline; say "$arr[0], \t $arr[8]"; =head OUTPUT: XP.sta1, -42.2436 =cut

UPDATE: Your pseudocode (I hope it was intended as pseudocode) is far from actually useful and makes very little sense in terms of your problem statement. Something on this order might serve you better:

use 5.018; use Data::Dumper; my $mFile='DATA1127720.txt'; # OP's sample data open(my $tablec, "<", "$mFile") or die "Can't open the datafile: $!"; my @tablec = <$tablec>; for (@tablec) { my @XPinfo = split /\s+/, $_; chomp @XPinfo; my $delayTime = $XPinfo[8]; if ( $delayTime < -10 ) { say "\t OUT OF BOUNDS!!! \$delayTime: $delayTime"; }else{ say $delayTime; # revision to save desired lines left as an e +xercise } } =head EXECUTION D:\>perl 1127720FIXED.pl OUT OF BOUNDS!!! $delayTime: -42.2436 2.5545 2.6160 2.6006 =cut

Your questions will benefit from careful use of language. Your "code so far" could be read as reflecting the PM admonition 'show us your code' ONLY if it accurately reflected your question ...and were it compilable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1127809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-29 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found