LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-12-2011, 02:38 AM   #1
umix
LQ Newbie
 
Registered: Oct 2011
Posts: 13

Rep: Reputation: Disabled
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
 
Old 10-12-2011, 02:55 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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
 
Old 10-12-2011, 03:02 AM   #3
umix
LQ Newbie
 
Registered: Oct 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-12-2011, 03:14 AM   #4
kartagien
LQ Newbie
 
Registered: Apr 2011
Posts: 5

Rep: Reputation: 0
Smile

I can't understand your problem very well !!
 
Old 10-12-2011, 03:20 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@umix: As stated in my previous reply: You need to use [code] [/code] tags around your example!
 
Old 10-12-2011, 04:12 AM   #6
umix
LQ Newbie
 
Registered: Oct 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-12-2011, 04:34 AM   #7
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Try out this
Code:
awk -F" " ' $2 != "" { print } ' /path/to/your/file > /path/to/the/desired/file
 
0 members found this post helpful.
Old 10-12-2011, 05:20 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 10-12-2011, 06:33 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,009

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Let us keep it simple:
Code:
awk 'NF > 2' infile > outfile
Or can the first or third columns be blank?
 
Old 10-13-2011, 12:59 AM   #10
umix
LQ Newbie
 
Registered: Oct 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
thanks a lot for all valuable suggestions..it helped me to solve
 
Old 10-13-2011, 01:26 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,009

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Remember to mark as SOLVED.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gnome-terminal is missing one pixel row and its an important row rednuht Linux - General 1 12-24-2009 10:30 AM
transpose row to column? resolute155 Programming 3 09-07-2009 02:29 PM
Shell script to parse csv-like output, row by row utahnix Linux - General 8 12-08-2007 05:03 AM
vi editor - how to delete a character in each row of a column? flipwhy Linux - Newbie 6 01-22-2007 02:12 PM
Transposing a column into a row mayyash Linux - General 1 09-30-2005 02:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration