The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to remove all empty files within the directory structure? cat123 Shell Programming and Scripting 5 06-05-2008 06:01 AM
remove empty directory sirrtuan Shell Programming and Scripting 6 03-04-2008 05:50 AM
Shell Script using Join, empty field help! tibbyuk UNIX for Dummies Questions & Answers 1 02-25-2008 08:33 AM
remove space in front or end of each field happyv Shell Programming and Scripting 6 03-21-2007 10:05 PM
Remove non empty dirctory adol3 SUN Solaris 5 12-13-2005 10:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
Stumble this Post!
Awk scrip to remove empty field

Hi

I have a file which looks like this

name: Sally group: Group4
name: Tim group: Group1
name: Dan group: Group2
name: Chris group: Group3
name: Peter group:
name: Fred group:
name: Mary group: Group2


Well I want to get rid of the ones that the group are empty looking like this

name: Sally group: Group4
name: Tim group: Group1
name: Dan group: Group2
name: Chris group: Group3
name: Mary group: Group2

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-11-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,536
Stumble this Post!
If there are no blanks after the colon:

Code:
grep -v :\$ filename
Otherwise:

Code:
grep -v ': *$' file
Reply With Quote
  #3 (permalink)  
Old 06-11-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,953
Stumble this Post!
Another one:

Code:
awk '$4' file
Reply With Quote
  #4 (permalink)  
Old 06-11-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,536
Stumble this Post!
-1

Code:
awk \$4 file
Reply With Quote
  #5 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
Stumble this Post!
Thanks guys ! Works

grep -v ': *$' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0