LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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, 12:26 PM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,135

Rep: Reputation: 299Reputation: 299Reputation: 299
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, 12:47 PM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 638

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
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, 12:55 PM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,562

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
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, 01:08 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,135

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


All times are GMT -5. The time now is 07:50 AM.

Main Menu
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