LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find a null value in a row/column and delete entire row (https://www.linuxquestions.org/questions/linux-newbie-8/find-a-null-value-in-a-row-column-and-delete-entire-row-907724/)

umix 10-12-2011 02:38 AM

find a null value in a row/column and delete entire row
 
hey guys..
my source looks like this

1 a g
2 j f
352 k i
4 g r
4 b
4 f k
4 l
5 c d
5 k
5 r j

i want to delete the 5th,7th and 9th row as it contains null in second column

i am newbie to linux so i would appreciated any kind of help.
thanks

druuna 10-12-2011 02:55 AM

Hi and welcome to LQ!

Please put your script/data inside [code] ... [/code] tags it preserves all spacing. If you don't know how: LQ - BB Code List.

The example given in your first post looks the same for all entries, using code tags might give a better view on your problem.

Hope this helps

umix 10-12-2011 03:02 AM

thanks druuna
here i am highlighting the rows that have to be removed

1 a g
2 j f
352 k i
4 g r
4 b
4 f k
4 l
5 c d
5 k
5 r j

kartagien 10-12-2011 03:14 AM

I can't understand your problem very well !!

druuna 10-12-2011 03:20 AM

@umix: As stated in my previous reply: You need to use [code] [/code] tags around your example!

umix 10-12-2011 04:12 AM

ok i got it

Code:

1 a g
2 j f
352 k i
4 g r
4  b
4 f k
4  l
5 c d
5  k
5 r j


tshikose 10-12-2011 04:34 AM

Try out this
Code:

awk -F" " ' $2 != "" { print } ' /path/to/your/file > /path/to/the/desired/file

druuna 10-12-2011 05:20 AM

Hi,

tshikose's solution doesn't work when using your example , try one of these:

Code:

# using awk:
awk '!/  / { print }' infile > outfile

# using sed:
sed -i.bak '/  /d' infile

The -i.bak in the sed command changes the original and creates a backup of the original.

Hope this helps.

grail 10-12-2011 06:33 AM

Let us keep it simple:
Code:

awk 'NF > 2' infile > outfile
Or can the first or third columns be blank?

umix 10-13-2011 12:59 AM

thanks a lot for all valuable suggestions..it helped me to solve

grail 10-13-2011 01:26 AM

Remember to mark as SOLVED.


All times are GMT -5. The time now is 06:01 AM.