Deleting row if all column values are a particular string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting row if all column values are a particular string
# 8  
Old 10-19-2012
This is what I type:

mep74-1Smilieesktop morganmouchka$ awk '{n=0;for(i=2;i<=5;i++) if ($i+0!=0) n++}n' FS=',' AT_counts.txt

And nothing prints on the screen and it directs me to the next command line. (i.e. mep74-1Smilieesktop morganmouchka$
# 9  
Old 10-19-2012
Quote:
Originally Posted by vgersh99
Code:
awk '{n=0;for(i=2;i<=5;i++) if ($i+0!=0) n++}n' FS=',' myFile

This will also remove those lines whose 2nd,3rd,4th or 5th fields have either zeroes, white-space, null values or a string starting with a non-digit character (with or without white-space at the beginning).

Last edited by elixir_sinari; 10-19-2012 at 02:09 PM..
# 10  
Old 10-19-2012
Quote:
Originally Posted by mouchkam
This is what I type:

Code:
mep74-1:Desktop morganmouchka$ awk '{n=0;for(i=2;i<=5;i++) if ($i+0!=0) n++}n' FS=',' AT_counts.txt

And nothing prints on the screen and it directs me to the next command line. (i.e. mep74-1Smilieesktop morganmouchka$
Check your AT_counts.txt file - make sure it's formatted as your posted file. Any ^M characters?
I quoted the output of the script ran against your sample file above.
# 11  
Old 10-19-2012
Quote:
Originally Posted by vgersh99
Check your AT_counts.txt file - make sure it's formatted as your posted file. Any ^M characters?
I quoted the output of the script ran against your sample file above.
Okay...the data above was just made-up data to avoid the lengthy name of contigs. My data is in a tab delimited text file and looks as follows:

Code:
Locus_36635_Transcript_1/1_Confidence_1.000_Length_246    0    0    0    0
Locus_21231_Transcript_1/1_Confidence_1.000_Length_443    0    0    0    0
Locus_6145_Transcript_1/1_Confidence_1.000_Length_2892    0    0    0    0
Locus_16925_Transcript_1/1_Confidence_1.000_Length_838    0    0    0    0
Locus_125599_Transcript_2/4_Confidence_1.000_Length_409    0    2    0    4
Locus_90716_Transcript_1/1_Confidence_0.000_Length_1868    0    0    0    0

I'm obviously very new to Unix/Linux and I'm not sure I understand what ^M characters are or how to remove them? Should I used a different file format?
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 10-19-2012 at 02:45 PM.. Reason: once again - please use code tags!
# 12  
Old 10-19-2012
Code:
 
awk '!($2==0 && $3==0 && $4==0 && $5==0)' infile

# 13  
Old 10-19-2012
Quote:
Originally Posted by rdrtx1
Code:
 
awk '!($2==0 && $3==0 && $4==0 && $5==0)' infile

When I run this code, it removes all rows with any zeros in columns 2-5 (e.g. 0 0 1 1 or
0 1 1 1 get removed), not just rows for which there are zeros in every column (e.g. 0 0 0 0 ).
# 14  
Old 10-19-2012
Quote:
Originally Posted by elixir_sinari
This will also remove those lines whose 2nd,3rd,4th or 5th fields have either zeroes, white-space, null values or a string starting with a non-digit character (with or without white-space at the beginning).
true, but your suggestion doesn't pick the all-zero condition (at least under Cygwin).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

How to add one to each row values and keep it after the value in the column?

Dear Folks Hello I have a column of numbers, say: 26 79 68 I want to add one to each row value and get this desire column: 26 27 79 80 68 69 (6 Replies)
Discussion started by: sajmar
6 Replies

2. Shell Programming and Scripting

Parsing Column Values in Row

Hi , I have been trying to write a awk script which will have the following Output 1. Append the last Characters of the lines matching pattern xxxxxxxxx & then a space & then Append the last Characters of the lines matching pattern yyyyyyyyy 2. the process will continue till end of file &... (10 Replies)
Discussion started by: newageBATMAN
10 Replies

3. Shell Programming and Scripting

Remove the values from a certain column without deleting the Column name in a .CSV file

(14 Replies)
Discussion started by: dhruuv369
14 Replies

4. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Deleting a row based on fetched value of column

Hi, I have a file which consists of two columns but the first one can be varying in length like 123456789 0abcd 123456789 0abcd 4015 0 0abcd 5000 0abcd I want to go through the file reading each line, count the number of characters in the first column and delete... (2 Replies)
Discussion started by: swasid
2 Replies

6. Shell Programming and Scripting

Arrange values of a column in row

HI, I need to arrange values of a colum in row. e.g. input file : Alpha<>123 AAAA<>6754 Beta<>456 BBBB<>63784 CCC<>783 Gama<>789 Alpha<>555 AAAA<>6754 BBBB<>63784 Beta<>666 CCC<>783 Gama<>888 (9 Replies)
Discussion started by: The_Archer
9 Replies

7. UNIX for Dummies Questions & Answers

deleting a row if a certain column is below a certain number

How can you delete a row if a certain column is bigger than a certain number? I have the following input: 20080709 20081222 95750 1 0 0.02 94.88 20080709 20081222 95750 2 0 0.89 94.88 20080709 20081222 9575 1 0 0 94.88 20080709 20081222 9575 2 0 0 94.88 20080709 20081222 9587.5 1 0 0... (6 Replies)
Discussion started by: Pep Puigvert
6 Replies

8. UNIX for Dummies Questions & Answers

deleting a row if a certain column is below a certain number

How can you delete a row if a certain column is bigger than a certain number? I have the following input: 20080709 20081222 95750 1 0 0.02 94.88 20080709 20081222 95750 2 0 0.89 94.88 20080709 20081222 9575 1 0 0 94.88 20080709 20081222 9575 2 0 0 94.88 20080709 20081222 9587.5 1 0 0... (1 Reply)
Discussion started by: Pep Puigvert
1 Replies

9. Shell Programming and Scripting

Converting values in a ROW to COLUMN

Hi All, I needd to convert values in a row to a column. eg: Input is as: value1,value2,value3,value4,.........,value N Required Output: Value1 Value2 Value3 . . . Value N Please help.... (3 Replies)
Discussion started by: sambaman
3 Replies
Login or Register to Ask a Question