delete rows with a criteria


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers delete rows with a criteria
# 1  
Old 04-26-2012
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
# 2  
Old 04-26-2012
Please provide an input sample and desired output and what you have tried so far..
# 3  
Old 04-26-2012
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 04:22 PM.. Reason: code tags
# 4  
Old 04-26-2012
Perhaps:
Code:
egrep -v "^[^ ]+ +[^ ]+( +0)*$" filename > outfile

# 5  
Old 04-26-2012
another way
Code:
awk '{x=0;for(i=3;i<=NF;i++)x+=$i}x>0' infile

# 6  
Old 04-26-2012
Code:
awk '$3||$4||$5||$6||$7' infile

These 2 Users Gave Thanks to Scrutinizer For This Post:
# 7  
Old 04-27-2012
Code:
awk '{for(i=3;i<=NF;i++)if($i>0){print;next}}' input.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete duplicate row based on criteria

Hi, I have an input file as shown below: 20140102;13:30;FR-AUD-LIBOR-1W;2.495 20140103;13:30;FR-AUD-LIBOR-1W;2.475 20140106;13:30;FR-AUD-LIBOR-1W;2.495 20140107;13:30;FR-AUD-LIBOR-1W;2.475 20140108;13:30;FR-AUD-LIBOR-1W;2.475 20140109;13:30;FR-AUD-LIBOR-1W;2.475... (2 Replies)
Discussion started by: shash
2 Replies

2. Shell Programming and Scripting

Rows to Columns with match criteria

Hello Friends, I have a input file having hundreds of rows. I want them to translate in to columns if column 1 is same. Input data: zp06 xxx zp06 rrr zp06 hhh zp06 aaa zp06 ggg zp06 qwer zp06 ser zl11 old3 zl11 old4 zl11 old5 zl11 old6 zl11 old7 zm14 luri zm14 body zm14 ucp (9 Replies)
Discussion started by: suresh3566
9 Replies

3. UNIX for Dummies Questions & Answers

How to delete rows?

I have an Output file which has the result YYYY 95,77 YYYY YYYY 95 YYYY 95 YYYY 95 YYYY 95 YYYY 95 YYYY 95 YYYY 95 YYYY 95 YYYY YYYY YYYY YYYY I would like to display the above along with a single line with above info. Final output should be YYYY 95 (3 Replies)
Discussion started by: priyanka.premra
3 Replies

4. Shell Programming and Scripting

Need To Delete Lines Based On Search Criteria

Hi All, I have following input file. I wish to retain those lines which match multiple search criteria. The search criteria is stored in a variable seperated from each other by comma(,). SEARCH_CRITERIA = "REJECT, DUPLICATE" Input File: ERROR,MYFILE_20130214_11387,9,37.75... (3 Replies)
Discussion started by: angshuman
3 Replies

5. Shell Programming and Scripting

delete the same rows

each individual (row) has genotype expressed for each SNP (column) file1.txt 1 1 A G A T G T A A A A A A A A A A A A A A A A A A A A A 2 2 G A A A A A A A A A A A A A A A A A A A A A A A A A A 3 3 A A A A A A A A A A A A A A A A A A A A A A A A A A A 4 4 G A G T A T A A A A A A A A A A A... (3 Replies)
Discussion started by: johnkim0806
3 Replies

6. Shell Programming and Scripting

pull out rows with specific criteria

Hi, I have a file with multiple columns and for column 5 I want to extract that row into another file if it is equal to or greater than a certain value. For example: FAR 4 5 7 LOP GAT 3 3 3 POL I want values that are greater than 5 for column 4. So the final file will look like... (1 Reply)
Discussion started by: phil_heath
1 Replies

7. Shell Programming and Scripting

awk search & delete located criteria

Guys, I manages to get awk to search and print the files that I want to delete. However I am stuck on the delete portion. Here is the command that I am using to fins these files. find /usr/local/apache/conf/vhosts/ -type f | awk '/e$/' The output is perfect. The files look like so: ... (4 Replies)
Discussion started by: jaysunn
4 Replies

8. Shell Programming and Scripting

delete rows in a file based on the rows of another file

I need to delete rows based on the number of lines in a different file, I have a piece of code with me working but when I merge with my C application, it doesnt work. sed '1,'\"`wc -l < /tmp/fileyyyy`\"'d' /tmp/fileA > /tmp/filexxxx Can anyone give me an alternate solution for the above (2 Replies)
Discussion started by: Muthuraj K
2 Replies

9. Shell Programming and Scripting

Delete new lines based on search criteria

Hi all! A bit of background: I am trying to create a script that formats SQL statements. I have gotten so far as to add new lines based on certain match criteria like commas, keywords etc. In the process, I end up adding newlines where I don't want. For example: substr(colName, 1, 10)... (3 Replies)
Discussion started by: jayarkay
3 Replies

10. Shell Programming and Scripting

Selecting rows with a specific criteria

Hi, I want a UNIX command that can filter out rows with certain criteria. The file is tab deliminated. Row one is just a value. Basically what I want to do is select based on the name and character at the end (o). So lets lets say i want a row that has WashU and (o) then it would print... (2 Replies)
Discussion started by: phil_heath
2 Replies
Login or Register to Ask a Question