The UNIX and Linux Forums  

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
How can i replace a character with blank space? rollthecoin AIX 8 04-22-2008 09:55 AM
[bash] Check if variable is set or blank noratx Shell Programming and Scripting 1 03-28-2008 09:42 AM
how to check weather file is blank or not? jaydeep_sadaria Shell Programming and Scripting 5 12-15-2007 08:35 AM
how to check first character in var's value. yongho UNIX for Dummies Questions & Answers 7 07-01-2005 12:22 PM
awk: How to check if field is blank? yongho Shell Programming and Scripting 7 06-09-2005 12:35 PM

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 10-21-2003
anthreedhr anthreedhr is offline
Registered User
  
 

Join Date: Sep 2003
Location: Indianapolis, IN USA
Posts: 10
check for the first character to be blank

I'm having a problem when the first line or first character of a file is blank. I need to get rid of both of them when they occur but don't want to delete the line. Does anyone have any suggestions?
  #2 (permalink)  
Old 10-21-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
if the line is blank is it padded w/ spaces kinda blank or is a carriage return?
  #3 (permalink)  
Old 10-21-2003
anthreedhr anthreedhr is offline
Registered User
  
 

Join Date: Sep 2003
Location: Indianapolis, IN USA
Posts: 10
looks like it's padded with a space on the blank line.
  #4 (permalink)  
Old 10-21-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006

Code:
sed 's/^ *//' file1|sed '/^$/d'|sed '/^ $/d' > file2

# cat file1

Line 2
 Line 3
  Line 4

# cat file2
Line 2
Line 3
Line 4
#

im sure there is a way to make it look prettier then invokeing sed 3x but it works.
  #5 (permalink)  
Old 10-21-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
I think that last SED command should actually be sed '/^ *$/d'.

Also, maybe this'll be faster than invoking SED three times:
sed -e 's/^ *//' -e '/^$/d' -e '/^ *$/d' file1 > file2
  #6 (permalink)  
Old 10-21-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Quote:
Originally posted by oombera
I think that last SED command should actually be sed '/^ *$/d'.

Also, maybe this'll be faster than invoking SED three times:
sed -e 's/^ *//' -e '/^$/d' -e '/^ *$/d' file1 > file2
see i knew someone wouldnt be as sloppy as me.
  #7 (permalink)  
Old 10-22-2003
anthreedhr anthreedhr is offline
Registered User
  
 

Join Date: Sep 2003
Location: Indianapolis, IN USA
Posts: 10
Thanks oombera and optimus... both of the solutions each of you gave worked like a charm. I tried sometime similar to the end of the line as well.. with some mixed success.

Thanks again for your assistance.... and if you have any suggestions on how to get rid of the space at the end of the line, let me know. Harold
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 02:37 PM.


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