LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Suffix blank lines with text (http://www.linuxquestions.org/questions/programming-9/suffix-blank-lines-with-text-4175440471/)

danielbmartin 12-07-2012 01:26 PM

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

firstfire 12-07-2012 01:47 PM

Hi.

Maybe you need to remove the dot in front of *:
Code:

sed 's/^\([[:space:]]*\)$/\1EOL/' $InFile

grail 12-07-2012 01:55 PM

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

danielbmartin 12-07-2012 02:08 PM

Quote:

Originally Posted by firstfire (Post 4844723)
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 (Post 4844727)
Code:

sed 's/^[[:space:]]*$/&EOL/' file

Perfect solution! Thank you!

Daniel B. Martin


All times are GMT -5. The time now is 01:23 PM.