Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-26-2012
Registered User
 
Join Date: Dec 2008
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
delete rows with a criteria

Hi,

I would like to know how can I delete rows of a text file if from the 3rd column onwards there is only zeros?

Thanks in advance
Sponsored Links
    #2  
Old 04-26-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,394
Thanks: 144
Thanked 1,757 Times in 1,594 Posts
Please provide an input sample and desired output and what you have tried so far..
Sponsored Links
    #3  
Old 04-26-2012
Registered User
 
Join Date: Dec 2008
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks for the reply.

Example Input file:


Code:
a b 0 0 0 0 0
a d 0 1 0 0 1.5
d r 0 0 0 0 0

Desired output file:


Code:
a d 0 1 0 0 1.5


Last edited by Scrutinizer; 04-26-2012 at 03:22 PM.. Reason: code tags
    #4  
Old 04-26-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,407
Thanks: 492
Thanked 2,538 Times in 2,421 Posts
Perhaps:
Code:
egrep -v "^[^ ]+ +[^ ]+( +0)*$" filename > outfile

Sponsored Links
    #5  
Old 04-26-2012
Registered User
 
Join Date: Jul 2008
Location: NY
Posts: 203
Thanks: 13
Thanked 39 Times in 38 Posts
another way

Code:
awk '{x=0;for(i=3;i<=NF;i++)x+=$i}x>0' infile

Sponsored Links
    #6  
Old 04-26-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,394
Thanks: 144
Thanked 1,757 Times in 1,594 Posts

Code:
awk '$3||$4||$5||$6||$7' infile

The Following 2 Users Say Thank You to Scrutinizer For This Useful Post:
47shailesh (04-26-2012), shamrock (04-26-2012)
Sponsored Links
    #7  
Old 04-27-2012
itkamaraj's Avatar
^Kamaraj^
 
Join Date: Apr 2010
Posts: 3,025
Thanks: 33
Thanked 647 Times in 625 Posts

Code:
awk '{for(i=3;i<=NF;i++)if($i>0){print;next}}' input.txt

Sponsored Links
Closed Thread

Tags
delete rows

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete duplicate rows jacobs.smith Shell Programming and Scripting 5 04-24-2012 02:42 PM
awk search & delete located criteria jaysunn Shell Programming and Scripting 4 03-12-2010 12:34 PM
delete rows in a file based on the rows of another file Muthuraj K Shell Programming and Scripting 2 01-22-2010 03:03 AM
Delete new lines based on search criteria jayarkay Shell Programming and Scripting 3 01-19-2010 01:36 AM
Selecting rows with a specific criteria phil_heath Shell Programming and Scripting 2 07-19-2009 11:02 PM



All times are GMT -4. The time now is 11:42 PM.