LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 12-07-2012, 01:26 PM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,167

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Suffix blank lines with text


Have: a file such that some lines contain readable text and some lines are "blank."
The lines with readable text may have leading and/or trailing blanks.
The "blank" lines may contain zero or more blanks.

Want: a sed which suffixes the "blank" lines with a readable character string such as "EOL".
No blanks may be added or destroyed.

I tried this ...
Code:
sed 's/^\([[:space:]].*\)$/\1EOL/' $InFile
... but it doesn't do the job.

Please advise.

Daniel B. Martin
 
Old 12-07-2012, 01:47 PM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 640

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Hi.

Maybe you need to remove the dot in front of *:
Code:
sed 's/^\([[:space:]]*\)$/\1EOL/' $InFile
 
1 members found this post helpful.
Old 12-07-2012, 01:55 PM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
If you want only the blank lines ... why use '.'? I thought the idea was a blank line may have whitespace but nothing else?
Code:
sed 's/^[[:space:]]*$/&EOL/' file
 
1 members found this post helpful.
Old 12-07-2012, 02:08 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,167

Original Poster
Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Quote:
Originally Posted by firstfire View Post
Code:
sed 's/^\([[:space:]]*\)$/\1EOL/' $InFile
Perfect solution! Thank you!

Daniel B. Martin

---------- Post added 12-07-12 at 02:09 PM ----------

Quote:
Originally Posted by grail View Post
Code:
sed 's/^[[:space:]]*$/&EOL/' file
Perfect solution! Thank you!

Daniel B. Martin
 
  


Reply

Tags
sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Make multiple blank lines to a single lines kimhj3715 Programming 5 06-10-2012 11:35 AM
[SOLVED] Perl: how to replace blank lines in a file with given lines from another karamaz0v Programming 8 04-19-2012 07:48 AM
Inserting blank lines in text file David the H. Linux - General 5 11-24-2007 04:34 PM
removing blank lines in a text file christianunix Linux - Newbie 11 10-29-2007 01:24 AM
Replace blank/almost blank lines in file Wynd Linux - General 3 01-27-2004 05:49 PM


All times are GMT -5. The time now is 11:51 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration