The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
delete traling blank lines only visu UNIX for Dummies Questions & Answers 1 03-05-2008 09:09 PM
delete blank lines from a file sachin.gangadha UNIX for Dummies Questions & Answers 2 12-04-2007 07:13 PM
Delete blank lines at the end of file TL56 Shell Programming and Scripting 3 10-25-2007 03:44 PM
delete blank lines with sed tmxps Shell Programming and Scripting 2 08-21-2007 07:01 PM
How to count lines - ignoring blank lines and commented lines kthatch UNIX for Dummies Questions & Answers 6 05-25-2007 01:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-10-2004
vascobrito vascobrito is offline
Registered User
  
 

Join Date: Oct 2003
Posts: 33
delete blank lines or lines with spaces only

hi there
i'm trying to delete blank lines and or lines with spaces only from a series of files in an directory.
to do so, i'm using this:

for files in `ls /users/myname/pesop* 2>/dev/null`
do
grep -v ^$ $files > newfile
mv newfile $files
done

now, this works great for blank lines but doesn't work for lines with spaces. The number of spaces is uncertain.
maybe it would be better with SED, but i dont know how to use it.
can anyone help me?
thanks
  #2 (permalink)  
Old 01-12-2004
jayakhanna jayakhanna is offline
Registered User
  
 

Join Date: Dec 2003
Location: India
Posts: 50
egrep -v " +" filename

This will do the trick of removing more than one spaces line also

Regards
JK
  #3 (permalink)  
Old 01-12-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,402
This will remove blank lines and those which only contain spaces...

grep -v '^ *$' $files

If you wanted to use sed, then...

sed '/^ *$/d' $files
  #4 (permalink)  
Old 01-13-2004
vascobrito vascobrito is offline
Registered User
  
 

Join Date: Oct 2003
Posts: 33
Thanks
It worked great.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0