|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Please provide an input sample and desired output and what you have tried so far..
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
Perhaps: Code:
egrep -v "^[^ ]+ +[^ ]+( +0)*$" filename > outfile |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
another way Code:
awk '{x=0;for(i=3;i<=NF;i++)x+=$i}x>0' infile |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
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
|
||||
|
||||
|
Code:
awk '{for(i=3;i<=NF;i++)if($i>0){print;next}}' input.txt |
| Sponsored Links | ||
|
![]() |
| Tags |
| delete rows |
| Thread Tools | Search this Thread |
| 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 |
|
|