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 > 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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to Remove the unwanted Blank Lines Ariean UNIX for Advanced & Expert Users 5 01-28-2009 02:20 PM
Remove all blank lines in shell or awk. tushar_tus Shell Programming and Scripting 1 10-13-2008 02:07 AM
remove blank lines in *.srt file :) hungbp UNIX for Dummies Questions & Answers 10 02-16-2008 08:40 AM
How to count lines - ignoring blank lines and commented lines kthatch UNIX for Dummies Questions & Answers 6 05-25-2007 01:21 AM
Remove blank lines osymad UNIX for Dummies Questions & Answers 4 08-27-2005 06:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-25-2009
gholdbhurg gholdbhurg is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 26
Shell script: Remove blank lines

Hi gurus,

I have this file with blank lines in it.
How do i remove them in shell?
I tried these commands but not working:
sed '/^ *$/d'
or
sed '/^$/d'
Anybody has a better idea pls?

Also there are lines which starts with a single space, how do we remove the space in those lines?
Thanks.
  #2 (permalink)  
Old 02-25-2009
vbe's Avatar
vbe vbe is online now Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,575
sed '/^$/d'
Should have worked, maybe line not so blank after all...
  #3 (permalink)  
Old 02-25-2009
ShawnMilo ShawnMilo is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 252
Quote:
Originally Posted by vbe View Post
sed '/^$/d'
Should have worked, maybe line not so blank after all...
To see exactly what's in the file, try this:

Code:
od -c file_name
Maybe there are non-printable characters.
  #4 (permalink)  
Old 02-25-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
or. . . . .

Code:
grep "[!-~]" file1 > file2
only grabs lines with SOMETHING ASCII in there other than just a space.
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 11:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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